From e44295ca2005c81e17fcdfa1b9da44275f0a3e45 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 13 Sep 2017 14:22:11 +0200 Subject: Benchmark incremental queries --- tests/mailquerybenchmark.cpp | 59 +++++++++++++++++++++++++++++++++++++++++--- tests/testimplementations.h | 5 ++++ 2 files changed, 60 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp index 00c156d..ca1e026 100644 --- a/tests/mailquerybenchmark.cpp +++ b/tests/mailquerybenchmark.cpp @@ -51,16 +51,18 @@ class MailQueryBenchmark : public QObject QByteArray resourceIdentifier; HAWD::State mHawdState; - void populateDatabase(int count, int folderSpreadFactor = 0) + void populateDatabase(int count, int folderSpreadFactor = 0, bool clear = true, int offset = 0) { - TestResource::removeFromDisk(resourceIdentifier); + if (clear) { + TestResource::removeFromDisk(resourceIdentifier); + } Sink::ResourceContext resourceContext{resourceIdentifier, "test", {{"mail", QSharedPointer::create()}}}; Sink::Storage::EntityStore entityStore{resourceContext, {}}; entityStore.startTransaction(Sink::Storage::DataStore::ReadWrite); const auto date = QDateTime::currentDateTimeUtc(); - for (int i = 0; i < count; i++) { + for (int i = offset; i < offset + count; i++) { auto domainObject = Mail::createEntity(resourceIdentifier); domainObject.setExtractedMessageId("uid"); domainObject.setExtractedParentMessageId("parentuid"); @@ -85,7 +87,6 @@ class MailQueryBenchmark : public QObject // Benchmark QTime time; time.start(); - auto resultSet = QSharedPointer>::create(); //FIXME why do we need this here? auto domainTypeAdaptorFactory = QSharedPointer::create(); @@ -178,6 +179,56 @@ private slots: populateDatabase(count, mailsPerFolder); testLoad("_threadleader", query, count, query.limit()); } + + void testIncremental() + { + Sink::Query query{Sink::Query::LiveQuery}; + query.request() + .request() + .request(); + query.sort(); + query.reduce(Query::Reduce::Selector::max()); + query.limit(1000); + + int count = 1000; + populateDatabase(count, 10); + auto expectedSize = 100; + QTime time; + time.start(); + auto domainTypeAdaptorFactory = QSharedPointer::create(); + Sink::ResourceContext context{resourceIdentifier, "test", {{"mail", domainTypeAdaptorFactory}}}; + context.mResourceAccess = QSharedPointer::create(); + TestMailResourceFacade facade(context); + + auto ret = facade.load(query, Sink::Log::Context{"benchmark"}); + ret.first.exec().waitForFinished(); + auto emitter = ret.second; + QList added; + QList removed; + QList modified; + emitter->onAdded([&](const Mail::Ptr &mail) { added << mail; /*qWarning() << "Added";*/ }); + emitter->onRemoved([&](const Mail::Ptr &mail) { removed << mail; /*qWarning() << "Removed";*/ }); + emitter->onModified([&](const Mail::Ptr &mail) { modified << mail; /*qWarning() << "Modified";*/ }); + bool done = false; + emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); + emitter->fetch(Mail::Ptr()); + QTRY_VERIFY(done); + QCOMPARE(added.size(), expectedSize); + + std::cout << "Initial query took: " << time.elapsed() << std::endl; + + populateDatabase(count, 10, false, count); + time.restart(); + context.mResourceAccess->revisionChanged(2000); + //We should have 200 items in total in the end. 2000 mails / 10 folders => 200 reduced mails + QTRY_COMPARE(added.count(), 200); + //For every email we have to redo the reduction and increase the count, which is a modification. + QTRY_COMPARE(modified.count(), 900); + std::cout << "Incremental query took " << time.elapsed() << std::endl; + std::cout << "added " << added.count() << std::endl; + std::cout << "modified " << modified.count() << std::endl; + std::cout << "removed " << removed.count() << std::endl; + } }; QTEST_MAIN(MailQueryBenchmark) diff --git a/tests/testimplementations.h b/tests/testimplementations.h index ff9d9b8..c7f4ce0 100644 --- a/tests/testimplementations.h +++ b/tests/testimplementations.h @@ -71,6 +71,11 @@ public: return KAsync::null(); } + void revisionUpdate(qint64 rev) + { + emit revisionChanged(rev); + } + public slots: void open() Q_DECL_OVERRIDE { -- cgit v1.2.3