diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-08 14:27:25 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-08 14:34:54 +0200 |
commit | 778b01181604dc2eae2013f2dc37db6d647b526a (patch) | |
tree | 739050aa453fe8adf140d8e6e65b870a10d8a39d /common/storage/entitystore.cpp | |
parent | 3657dcd309f30b704801dcaf3e43b71ef703c0de (diff) | |
download | sink-778b01181604dc2eae2013f2dc37db6d647b526a.tar.gz sink-778b01181604dc2eae2013f2dc37db6d647b526a.zip |
Gather required databases from index definitions.
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r-- | common/storage/entitystore.cpp | 73 |
1 files changed, 51 insertions, 22 deletions
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 @@ | |||
36 | using namespace Sink; | 36 | using namespace Sink; |
37 | using namespace Sink::Storage; | 37 | using namespace Sink::Storage; |
38 | 38 | ||
39 | static QMap<QByteArray, int> baseDbs() | ||
40 | { | ||
41 | return {{"revisionType", 0}, | ||
42 | {"revisions", 0}, | ||
43 | {"uids", 0}, | ||
44 | {"default", 0}, | ||
45 | {"__flagtable", 0}}; | ||
46 | } | ||
47 | |||
48 | template <typename T, typename First> | ||
49 | void mergeImpl(T &map, First f) | ||
50 | { | ||
51 | for (auto it = f.constBegin(); it != f.constEnd(); it++) { | ||
52 | map.insert(it.key(), it.value()); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | template <typename T, typename First, typename ... Tail> | ||
57 | void mergeImpl(T &map, First f, Tail ...maps) | ||
58 | { | ||
59 | for (auto it = f.constBegin(); it != f.constEnd(); it++) { | ||
60 | map.insert(it.key(), it.value()); | ||
61 | } | ||
62 | mergeImpl<T, Tail...>(map, maps...); | ||
63 | } | ||
64 | |||
65 | template <typename First, typename ... Tail> | ||
66 | First merge(First f, Tail ...maps) | ||
67 | { | ||
68 | First map; | ||
69 | mergeImpl(f, maps...); | ||
70 | return map; | ||
71 | } | ||
72 | |||
73 | template <class T> | ||
74 | struct DbLayoutHelper { | ||
75 | void operator()(QMap<QByteArray, int> map) const { | ||
76 | mergeImpl(map, ApplicationDomain::TypeImplementation<T>::typeDatabases()); | ||
77 | } | ||
78 | }; | ||
79 | |||
39 | static Sink::Storage::DbLayout dbLayout(const QByteArray &instanceId) | 80 | static Sink::Storage::DbLayout dbLayout(const QByteArray &instanceId) |
40 | { | 81 | { |
41 | return Sink::Storage::DbLayout { | 82 | static auto databases = [] { |
42 | instanceId, | 83 | QMap<QByteArray, int> map; |
43 | { | 84 | mergeImpl(map, ApplicationDomain::TypeImplementation<ApplicationDomain::Mail>::typeDatabases()); |
44 | {"folder.main", 0}, | 85 | mergeImpl(map, ApplicationDomain::TypeImplementation<ApplicationDomain::Folder>::typeDatabases()); |
45 | {"folder.index.name", 1}, | 86 | mergeImpl(map, ApplicationDomain::TypeImplementation<ApplicationDomain::Contact>::typeDatabases()); |
46 | {"folder.index.parent", 1}, | 87 | mergeImpl(map, ApplicationDomain::TypeImplementation<ApplicationDomain::Addressbook>::typeDatabases()); |
47 | {"mail.main", 0}, | 88 | mergeImpl(map, ApplicationDomain::TypeImplementation<ApplicationDomain::Event>::typeDatabases()); |
48 | {"mail.index.date", 1}, | 89 | return merge(baseDbs(), map); |
49 | {"mail.index.folder", 1}, | 90 | }(); |
50 | {"mail.index.folder.sort.date", 0}, | 91 | return {instanceId, databases}; |
51 | {"mail.index.messageId", 1}, | ||
52 | {"mail.index.messageIdthreadId", 1}, | ||
53 | {"mail.index.parentMessageId", 1}, | ||
54 | {"mail.index.subjectthreadId", 1}, | ||
55 | {"mail.index.threadIdmessageId", 1}, | ||
56 | {"revisionType", 0}, | ||
57 | {"revisions", 0}, | ||
58 | {"uids", 0}, | ||
59 | {"default", 0}, | ||
60 | {"__flagtable", 0} | ||
61 | } | ||
62 | }; | ||
63 | } | 92 | } |
64 | 93 | ||
65 | 94 | ||