From 778b01181604dc2eae2013f2dc37db6d647b526a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 8 May 2017 14:27:25 +0200 Subject: Gather required databases from index definitions. --- common/storage/entitystore.cpp | 73 +++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 22 deletions(-) (limited to 'common/storage') diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 9539bec..38ff730 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -36,30 +36,59 @@ using namespace Sink; using namespace Sink::Storage; +static QMap baseDbs() +{ + return {{"revisionType", 0}, + {"revisions", 0}, + {"uids", 0}, + {"default", 0}, + {"__flagtable", 0}}; +} + +template +void mergeImpl(T &map, First f) +{ + for (auto it = f.constBegin(); it != f.constEnd(); it++) { + map.insert(it.key(), it.value()); + } +} + +template +void mergeImpl(T &map, First f, Tail ...maps) +{ + for (auto it = f.constBegin(); it != f.constEnd(); it++) { + map.insert(it.key(), it.value()); + } + mergeImpl(map, maps...); +} + +template +First merge(First f, Tail ...maps) +{ + First map; + mergeImpl(f, maps...); + return map; +} + +template +struct DbLayoutHelper { + void operator()(QMap map) const { + mergeImpl(map, ApplicationDomain::TypeImplementation::typeDatabases()); + } +}; + static Sink::Storage::DbLayout dbLayout(const QByteArray &instanceId) { - return Sink::Storage::DbLayout { - instanceId, - { - {"folder.main", 0}, - {"folder.index.name", 1}, - {"folder.index.parent", 1}, - {"mail.main", 0}, - {"mail.index.date", 1}, - {"mail.index.folder", 1}, - {"mail.index.folder.sort.date", 0}, - {"mail.index.messageId", 1}, - {"mail.index.messageIdthreadId", 1}, - {"mail.index.parentMessageId", 1}, - {"mail.index.subjectthreadId", 1}, - {"mail.index.threadIdmessageId", 1}, - {"revisionType", 0}, - {"revisions", 0}, - {"uids", 0}, - {"default", 0}, - {"__flagtable", 0} - } - }; + static auto databases = [] { + QMap map; + mergeImpl(map, ApplicationDomain::TypeImplementation::typeDatabases()); + mergeImpl(map, ApplicationDomain::TypeImplementation::typeDatabases()); + mergeImpl(map, ApplicationDomain::TypeImplementation::typeDatabases()); + mergeImpl(map, ApplicationDomain::TypeImplementation::typeDatabases()); + mergeImpl(map, ApplicationDomain::TypeImplementation::typeDatabases()); + return merge(baseDbs(), map); + }(); + return {instanceId, databases}; } -- cgit v1.2.3