Changeset View
Changeset View
Standalone View
Standalone View
common/typeindex.cpp
Show First 20 Lines • Show All 421 Lines • ▼ Show 20 Line(s) | 418 | if (query.hasFilter(property)) { | |||
---|---|---|---|---|---|
422 | SinkTraceCtx(mLogCtx) << "Index lookup on " << property << " found " << keys.size() << " keys."; | 422 | SinkTraceCtx(mLogCtx) << "Index lookup on " << property << " found " << keys.size() << " keys."; | ||
423 | return keys; | 423 | return keys; | ||
424 | } | 424 | } | ||
425 | } | 425 | } | ||
426 | SinkTraceCtx(mLogCtx) << "No matching index"; | 426 | SinkTraceCtx(mLogCtx) << "No matching index"; | ||
427 | return {}; | 427 | return {}; | ||
428 | } | 428 | } | ||
429 | 429 | | |||
430 | QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant &value, | 430 | QVector<Identifier> TypeIndex::lookup(const QByteArray &property, const QVariant &value, | ||
431 | Sink::Storage::DataStore::Transaction &transaction) | 431 | Sink::Storage::DataStore::Transaction &transaction) | ||
432 | { | 432 | { | ||
433 | SinkTraceCtx(mLogCtx) << "Index lookup on property: " << property << mSecondaryProperties.keys() << mProperties; | 433 | SinkTraceCtx(mLogCtx) << "Index lookup on property: " << property << mSecondaryProperties.keys() << mProperties; | ||
434 | if (mProperties.contains(property)) { | 434 | if (mProperties.contains(property)) { | ||
435 | QVector<QByteArray> keys; | 435 | QVector<Identifier> keys; | ||
436 | Index index(indexName(property), transaction); | 436 | Index index(indexName(property), transaction); | ||
437 | const auto lookupKey = getByteArray(value); | 437 | const auto lookupKey = getByteArray(value); | ||
438 | index.lookup(lookupKey, | 438 | index.lookup(lookupKey, | ||
439 | [&](const QByteArray &value) { | 439 | [&](const QByteArray &value) { | ||
440 | keys << Identifier::fromInternalByteArray(value).toDisplayByteArray(); | 440 | keys << Identifier::fromInternalByteArray(value); | ||
441 | }, | 441 | }, | ||
442 | [property](const Index::Error &error) { | 442 | [property](const Index::Error &error) { | ||
443 | SinkWarning() << "Error in index: " << error.message << property; | 443 | SinkWarning() << "Error in index: " << error.message << property; | ||
444 | }); | 444 | }); | ||
445 | SinkTraceCtx(mLogCtx) << "Index lookup on " << property << " found " << keys.size() << " keys."; | 445 | SinkTraceCtx(mLogCtx) << "Index lookup on " << property << " found " << keys.size() << " keys."; | ||
446 | return keys; | 446 | return keys; | ||
447 | } else if (mSecondaryProperties.contains(property)) { | 447 | } else if (mSecondaryProperties.contains(property)) { | ||
448 | // Lookups on secondary indexes first lookup the key, and then lookup the results again to | 448 | // Lookups on secondary indexes first lookup the key, and then lookup the results again to | ||
449 | // resolve to entity id's | 449 | // resolve to entity id's | ||
450 | QVector<QByteArray> keys; | 450 | QVector<Identifier> keys; | ||
451 | auto resultProperty = mSecondaryProperties.value(property); | 451 | auto resultProperty = mSecondaryProperties.value(property); | ||
452 | 452 | | |||
453 | QVector<QByteArray> secondaryKeys; | 453 | QVector<QByteArray> secondaryKeys; | ||
454 | Index index(indexName(property + resultProperty), transaction); | 454 | Index index(indexName(property + resultProperty), transaction); | ||
455 | const auto lookupKey = getByteArray(value); | 455 | const auto lookupKey = getByteArray(value); | ||
456 | index.lookup(lookupKey, [&](const QByteArray &value) { secondaryKeys << value; }, | 456 | index.lookup(lookupKey, [&](const QByteArray &value) { secondaryKeys << value; }, | ||
457 | [property](const Index::Error &error) { | 457 | [property](const Index::Error &error) { | ||
458 | SinkWarning() << "Error in index: " << error.message << property; | 458 | SinkWarning() << "Error in index: " << error.message << property; | ||
459 | }); | 459 | }); | ||
460 | SinkTraceCtx(mLogCtx) << "Looked up secondary keys for the following lookup key: " << lookupKey | 460 | SinkTraceCtx(mLogCtx) << "Looked up secondary keys for the following lookup key: " << lookupKey | ||
461 | << " => " << secondaryKeys; | 461 | << " => " << secondaryKeys; | ||
462 | for (const auto &secondary : secondaryKeys) { | 462 | for (const auto &secondary : secondaryKeys) { | ||
463 | keys += lookup(resultProperty, secondary, transaction); | 463 | keys += lookup(resultProperty, secondary, transaction); | ||
464 | } | 464 | } | ||
465 | return keys; | 465 | return keys; | ||
466 | } else { | 466 | } else { | ||
467 | SinkWarning() << "Tried to lookup " << property << " but couldn't find value"; | 467 | SinkWarning() << "Tried to lookup " << property << " but couldn't find value"; | ||
468 | } | 468 | } | ||
469 | return QVector<QByteArray>(); | 469 | return {}; | ||
470 | } | 470 | } | ||
471 | 471 | | |||
472 | template <> | 472 | template <> | ||
473 | void TypeIndex::index<QByteArray, QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction) | 473 | void TypeIndex::index<QByteArray, QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction) | ||
474 | { | 474 | { | ||
475 | Index(indexName(leftName + rightName), transaction).add(getByteArray(leftValue), getByteArray(rightValue)); | 475 | Index(indexName(leftName + rightName), transaction).add(getByteArray(leftValue), getByteArray(rightValue)); | ||
476 | } | 476 | } | ||
477 | 477 | | |||
Show All 35 Lines |