diff options
author | Minijackson <minijackson@riseup.net> | 2018-07-13 17:15:53 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-07-13 17:15:53 +0200 |
commit | 1b5499770273913ad26b213406df4208b10e2b3c (patch) | |
tree | 85e13a65e7c6e702db3e6c433b95e718e7072148 /common/storage/entitystore.cpp | |
parent | d0ab46b20b74acef104038cbc5c1b769be863cd3 (diff) | |
download | sink-1b5499770273913ad26b213406df4208b10e2b3c.tar.gz sink-1b5499770273913ad26b213406df4208b10e2b3c.zip |
Finish converting DataStoreQuery to new Key API
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r-- | common/storage/entitystore.cpp | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index be51c2c..672eea1 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -461,11 +461,11 @@ QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const Query | |||
461 | return d->typeIndex(type).query(query, appliedFilters, appliedSorting, d->getTransaction(), d->resourceContext.instanceId()); | 461 | return d->typeIndex(type).query(query, appliedFilters, appliedSorting, d->getTransaction(), d->resourceContext.instanceId()); |
462 | } | 462 | } |
463 | 463 | ||
464 | QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value) | 464 | QVector<Identifier> EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value) |
465 | { | 465 | { |
466 | if (!d->exists()) { | 466 | if (!d->exists()) { |
467 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; | 467 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; |
468 | return QVector<QByteArray>(); | 468 | return {}; |
469 | } | 469 | } |
470 | return d->typeIndex(type).lookup(property, value, d->getTransaction()); | 470 | return d->typeIndex(type).lookup(property, value, d->getTransaction()); |
471 | } | 471 | } |
@@ -476,9 +476,9 @@ void EntityStore::indexLookup(const QByteArray &type, const QByteArray &property | |||
476 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; | 476 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; |
477 | return; | 477 | return; |
478 | } | 478 | } |
479 | auto list = d->typeIndex(type).lookup(property, value, d->getTransaction()); | 479 | auto list = indexLookup(type, property, value); |
480 | for (const auto &uid : list) { | 480 | for (const auto &id : list) { |
481 | callback(uid); | 481 | callback(id.toDisplayByteArray()); |
482 | } | 482 | } |
483 | /* Index index(type + ".index." + property, d->transaction); */ | 483 | /* Index index(type + ".index." + property, d->transaction); */ |
484 | /* index.lookup(value, [&](const QByteArray &sinkId) { */ | 484 | /* index.lookup(value, [&](const QByteArray &sinkId) { */ |
@@ -530,16 +530,7 @@ void EntityStore::readLatest(const QByteArray &type, const Identifier &uid, cons | |||
530 | 530 | ||
531 | void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomainType &, Sink::Operation)> callback) | 531 | void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomainType &, Sink::Operation)> callback) |
532 | { | 532 | { |
533 | // TODO: we shouldn't pass whole keys to this function | 533 | readLatest(type, Identifier::fromDisplayByteArray(uid), callback); |
534 | // check the testSingle test from querytest | ||
535 | const auto id = [&uid]() { | ||
536 | if(uid.size() == Identifier::DISPLAY_REPR_SIZE) { | ||
537 | return Identifier::fromDisplayByteArray(uid); | ||
538 | } else { | ||
539 | return Key::fromDisplayByteArray(uid).identifier(); | ||
540 | } | ||
541 | }(); | ||
542 | readLatest(type, id, callback); | ||
543 | } | 534 | } |
544 | 535 | ||
545 | ApplicationDomain::ApplicationDomainType EntityStore::readLatest(const QByteArray &type, const QByteArray &uid) | 536 | ApplicationDomain::ApplicationDomainType EntityStore::readLatest(const QByteArray &type, const QByteArray &uid) |
@@ -588,7 +579,7 @@ void EntityStore::readAll(const QByteArray &type, const std::function<void(const | |||
588 | }); | 579 | }); |
589 | } | 580 | } |
590 | 581 | ||
591 | void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedType, const std::function<void(const QByteArray &key)> &callback) | 582 | void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedType, const std::function<void(const Key &key)> &callback) |
592 | { | 583 | { |
593 | qint64 revisionCounter = baseRevision; | 584 | qint64 revisionCounter = baseRevision; |
594 | const qint64 topRevision = DataStore::maxRevision(d->getTransaction()); | 585 | const qint64 topRevision = DataStore::maxRevision(d->getTransaction()); |
@@ -607,15 +598,15 @@ void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedT | |||
607 | const auto key = Key(Identifier::fromDisplayByteArray(uid), revisionCounter); | 598 | const auto key = Key(Identifier::fromDisplayByteArray(uid), revisionCounter); |
608 | 599 | ||
609 | revisionCounter++; | 600 | revisionCounter++; |
610 | callback(key.toDisplayByteArray()); | 601 | callback(key); |
611 | } | 602 | } |
612 | } | 603 | } |
613 | 604 | ||
614 | void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) | 605 | void EntityStore::readPrevious(const QByteArray &type, const Identifier &id, qint64 revision, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) |
615 | { | 606 | { |
616 | auto db = DataStore::mainDatabase(d->getTransaction(), type); | 607 | auto db = DataStore::mainDatabase(d->getTransaction(), type); |
617 | qint64 latestRevision = 0; | 608 | qint64 latestRevision = 0; |
618 | const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); | 609 | const auto internalUid = id.toInternalByteArray(); |
619 | db.scan(internalUid, | 610 | db.scan(internalUid, |
620 | [&latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool { | 611 | [&latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool { |
621 | const auto foundRevision = Key::fromInternalByteArray(key).revision().toQint64(); | 612 | const auto foundRevision = Key::fromInternalByteArray(key).revision().toQint64(); |
@@ -625,21 +616,21 @@ void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qi | |||
625 | return true; | 616 | return true; |
626 | }, | 617 | }, |
627 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }, true); | 618 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }, true); |
628 | const auto key = Key(Identifier::fromDisplayByteArray(uid), latestRevision); | 619 | const auto key = Key(id, latestRevision); |
629 | readEntity(type, key.toDisplayByteArray(), callback); | 620 | readEntity(type, key.toDisplayByteArray(), callback); |
630 | } | 621 | } |
631 | 622 | ||
632 | void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomainType &)> callback) | 623 | void EntityStore::readPrevious(const QByteArray &type, const Identifier &id, qint64 revision, const std::function<void(const ApplicationDomainType &)> callback) |
633 | { | 624 | { |
634 | readPrevious(type, uid, revision, [&](const QByteArray &uid, const EntityBuffer &buffer) { | 625 | readPrevious(type, id, revision, [&](const QByteArray &uid, const EntityBuffer &buffer) { |
635 | callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer)); | 626 | callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer)); |
636 | }); | 627 | }); |
637 | } | 628 | } |
638 | 629 | ||
639 | ApplicationDomain::ApplicationDomainType EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision) | 630 | ApplicationDomain::ApplicationDomainType EntityStore::readPrevious(const QByteArray &type, const Identifier &id, qint64 revision) |
640 | { | 631 | { |
641 | ApplicationDomainType dt; | 632 | ApplicationDomainType dt; |
642 | readPrevious(type, uid, revision, [&](const ApplicationDomainType &entity) { | 633 | readPrevious(type, id, revision, [&](const ApplicationDomainType &entity) { |
643 | dt = *ApplicationDomainType::getInMemoryRepresentation<ApplicationDomainType>(entity, entity.availableProperties()); | 634 | dt = *ApplicationDomainType::getInMemoryRepresentation<ApplicationDomainType>(entity, entity.availableProperties()); |
644 | }); | 635 | }); |
645 | return dt; | 636 | return dt; |