summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-08 14:27:25 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-08 14:34:54 +0200
commit778b01181604dc2eae2013f2dc37db6d647b526a (patch)
tree739050aa453fe8adf140d8e6e65b870a10d8a39d
parent3657dcd309f30b704801dcaf3e43b71ef703c0de (diff)
downloadsink-778b01181604dc2eae2013f2dc37db6d647b526a.tar.gz
sink-778b01181604dc2eae2013f2dc37db6d647b526a.zip
Gather required databases from index definitions.
-rw-r--r--common/domain/typeimplementations.cpp78
-rw-r--r--common/domain/typeimplementations.h5
-rw-r--r--common/domain/typeimplementations_p.h154
-rw-r--r--common/mail/threadindexer.cpp7
-rw-r--r--common/mail/threadindexer.h1
-rw-r--r--common/storage/entitystore.cpp73
6 files changed, 278 insertions, 40 deletions
diff --git a/common/domain/typeimplementations.cpp b/common/domain/typeimplementations.cpp
index a87e73d..4e61bad 100644
--- a/common/domain/typeimplementations.cpp
+++ b/common/domain/typeimplementations.cpp
@@ -28,6 +28,7 @@
28#include "entity_generated.h" 28#include "entity_generated.h"
29#include "mail/threadindexer.h" 29#include "mail/threadindexer.h"
30#include "domainadaptor.h" 30#include "domainadaptor.h"
31#include "typeimplementations_p.h"
31 32
32using namespace Sink; 33using namespace Sink;
33using namespace Sink::ApplicationDomain; 34using namespace Sink::ApplicationDomain;
@@ -35,22 +36,43 @@ using namespace Sink::ApplicationDomain;
35#define SINK_REGISTER_SERIALIZER(MAPPER, ENTITYTYPE, PROPERTY, LOWERCASEPROPERTY) \ 36#define SINK_REGISTER_SERIALIZER(MAPPER, ENTITYTYPE, PROPERTY, LOWERCASEPROPERTY) \
36 MAPPER.addMapping<ENTITYTYPE::PROPERTY, Sink::ApplicationDomain::Buffer::ENTITYTYPE, Sink::ApplicationDomain::Buffer::ENTITYTYPE##Builder>(&Sink::ApplicationDomain::Buffer::ENTITYTYPE::LOWERCASEPROPERTY, &Sink::ApplicationDomain::Buffer::ENTITYTYPE##Builder::add_##LOWERCASEPROPERTY); 37 MAPPER.addMapping<ENTITYTYPE::PROPERTY, Sink::ApplicationDomain::Buffer::ENTITYTYPE, Sink::ApplicationDomain::Buffer::ENTITYTYPE##Builder>(&Sink::ApplicationDomain::Buffer::ENTITYTYPE::LOWERCASEPROPERTY, &Sink::ApplicationDomain::Buffer::ENTITYTYPE##Builder::add_##LOWERCASEPROPERTY);
37 38
39typedef IndexConfig<Mail,
40 ValueIndex<Mail::Date>,
41 ValueIndex<Mail::Folder>,
42 ValueIndex<Mail::ParentMessageId>,
43 ValueIndex<Mail::MessageId>,
44 SortedIndex<Mail::Folder, Mail::Date>,
45 SecondaryIndex<Mail::MessageId, Mail::ThreadId>,
46 SecondaryIndex<Mail::ThreadId, Mail::MessageId>,
47 CustomSecondaryIndex<Mail::MessageId, Mail::ThreadId, ThreadIndexer>
48 > MailIndexConfig;
49
50typedef IndexConfig<Folder,
51 ValueIndex<Folder::Name>,
52 ValueIndex<Folder::Parent>
53 > FolderIndexConfig;
54
55typedef IndexConfig<Contact,
56 ValueIndex<Contact::Uid>
57 > ContactIndexConfig;
58
59typedef IndexConfig<Addressbook,
60 ValueIndex<Addressbook::Parent>
61 > AddressbookIndexConfig;
62
63typedef IndexConfig<Event,
64 ValueIndex<Event::Uid>
65 > EventIndexConfig;
66
38 67
39void TypeImplementation<Mail>::configure(TypeIndex &index) 68void TypeImplementation<Mail>::configure(TypeIndex &index)
40{ 69{
41 // index.addProperty<Mail::Sender>(); 70 MailIndexConfig::configure(index);
42 /* index.addProperty<QByteArray>(Mail::SenderName::name); */ 71}
43 /* index->addProperty<QString>(Mail::Subject::name); */
44 /* index->addFulltextProperty<QString>(Mail::Subject::name); */
45 index.addProperty<Mail::Date>();
46 index.addProperty<Mail::Folder>();
47 index.addPropertyWithSorting<Mail::Folder, Mail::Date>();
48 index.addProperty<Mail::ParentMessageId>();
49 index.addProperty<Mail::MessageId>();
50 72
51 index.addSecondaryPropertyIndexer<Mail::MessageId, Mail::ThreadId, ThreadIndexer>(); 73QMap<QByteArray, int> TypeImplementation<Mail>::typeDatabases()
52 index.addSecondaryProperty<Mail::MessageId, Mail::ThreadId>(); 74{
53 index.addSecondaryProperty<Mail::ThreadId, Mail::MessageId>(); 75 return merge(QMap<QByteArray, int>{{QByteArray{Mail::name} + ".main", 0}}, MailIndexConfig::databases());
54} 76}
55 77
56void TypeImplementation<Mail>::configure(IndexPropertyMapper &indexPropertyMapper) 78void TypeImplementation<Mail>::configure(IndexPropertyMapper &indexPropertyMapper)
@@ -85,10 +107,15 @@ void TypeImplementation<Mail>::configure(PropertyMapper &propertyMapper)
85 SINK_REGISTER_SERIALIZER(propertyMapper, Mail, ParentMessageId, parentMessageId); 107 SINK_REGISTER_SERIALIZER(propertyMapper, Mail, ParentMessageId, parentMessageId);
86} 108}
87 109
110
88void TypeImplementation<Folder>::configure(TypeIndex &index) 111void TypeImplementation<Folder>::configure(TypeIndex &index)
89{ 112{
90 index.addProperty<QByteArray>(Folder::Parent::name); 113 FolderIndexConfig::configure(index);
91 index.addProperty<QString>(Folder::Name::name); 114}
115
116QMap<QByteArray, int> TypeImplementation<Folder>::typeDatabases()
117{
118 return merge(QMap<QByteArray, int>{{QByteArray{Folder::name} + ".main", 0}}, FolderIndexConfig::databases());
92} 119}
93 120
94void TypeImplementation<Folder>::configure(PropertyMapper &propertyMapper) 121void TypeImplementation<Folder>::configure(PropertyMapper &propertyMapper)
@@ -108,7 +135,12 @@ void TypeImplementation<Folder>::configure(IndexPropertyMapper &)
108 135
109void TypeImplementation<Contact>::configure(TypeIndex &index) 136void TypeImplementation<Contact>::configure(TypeIndex &index)
110{ 137{
111 index.addProperty<QByteArray>(Contact::Uid::name); 138 ContactIndexConfig::configure(index);
139}
140
141QMap<QByteArray, int> TypeImplementation<Contact>::typeDatabases()
142{
143 return merge(QMap<QByteArray, int>{{QByteArray{Contact::name} + ".main", 0}}, ContactIndexConfig::databases());
112} 144}
113 145
114void TypeImplementation<Contact>::configure(PropertyMapper &propertyMapper) 146void TypeImplementation<Contact>::configure(PropertyMapper &propertyMapper)
@@ -130,8 +162,12 @@ void TypeImplementation<Contact>::configure(IndexPropertyMapper &)
130 162
131void TypeImplementation<Addressbook>::configure(TypeIndex &index) 163void TypeImplementation<Addressbook>::configure(TypeIndex &index)
132{ 164{
133 index.addProperty<QByteArray>(Addressbook::Parent::name); 165 AddressbookIndexConfig::configure(index);
134 index.addProperty<QString>(Addressbook::Name::name); 166}
167
168QMap<QByteArray, int> TypeImplementation<Addressbook>::typeDatabases()
169{
170 return merge(QMap<QByteArray, int>{{QByteArray{Addressbook::name} + ".main", 0}}, AddressbookIndexConfig::databases());
135} 171}
136 172
137void TypeImplementation<Addressbook>::configure(PropertyMapper &propertyMapper) 173void TypeImplementation<Addressbook>::configure(PropertyMapper &propertyMapper)
@@ -148,7 +184,12 @@ void TypeImplementation<Addressbook>::configure(IndexPropertyMapper &)
148 184
149void TypeImplementation<Event>::configure(TypeIndex &index) 185void TypeImplementation<Event>::configure(TypeIndex &index)
150{ 186{
151 index.addProperty<QByteArray>(Event::Uid::name); 187 EventIndexConfig::configure(index);
188}
189
190QMap<QByteArray, int> TypeImplementation<Event>::typeDatabases()
191{
192 return merge(QMap<QByteArray, int>{{QByteArray{Event::name} + ".main", 0}}, EventIndexConfig::databases());
152} 193}
153 194
154void TypeImplementation<Event>::configure(PropertyMapper &propertyMapper) 195void TypeImplementation<Event>::configure(PropertyMapper &propertyMapper)
@@ -163,3 +204,4 @@ void TypeImplementation<Event>::configure(IndexPropertyMapper &)
163{ 204{
164 205
165} 206}
207
diff --git a/common/domain/typeimplementations.h b/common/domain/typeimplementations.h
index 7e4608c..d36dfc1 100644
--- a/common/domain/typeimplementations.h
+++ b/common/domain/typeimplementations.h
@@ -47,6 +47,7 @@ public:
47 static void configure(TypeIndex &index); 47 static void configure(TypeIndex &index);
48 static void configure(PropertyMapper &propertyMapper); 48 static void configure(PropertyMapper &propertyMapper);
49 static void configure(IndexPropertyMapper &indexPropertyMapper); 49 static void configure(IndexPropertyMapper &indexPropertyMapper);
50 static QMap<QByteArray, int> typeDatabases();
50}; 51};
51 52
52template<> 53template<>
@@ -57,6 +58,7 @@ public:
57 static void configure(TypeIndex &); 58 static void configure(TypeIndex &);
58 static void configure(PropertyMapper &); 59 static void configure(PropertyMapper &);
59 static void configure(IndexPropertyMapper &indexPropertyMapper); 60 static void configure(IndexPropertyMapper &indexPropertyMapper);
61 static QMap<QByteArray, int> typeDatabases();
60}; 62};
61 63
62template<> 64template<>
@@ -67,6 +69,7 @@ public:
67 static void configure(TypeIndex &); 69 static void configure(TypeIndex &);
68 static void configure(PropertyMapper &); 70 static void configure(PropertyMapper &);
69 static void configure(IndexPropertyMapper &indexPropertyMapper); 71 static void configure(IndexPropertyMapper &indexPropertyMapper);
72 static QMap<QByteArray, int> typeDatabases();
70}; 73};
71 74
72template<> 75template<>
@@ -77,6 +80,7 @@ public:
77 static void configure(TypeIndex &); 80 static void configure(TypeIndex &);
78 static void configure(PropertyMapper &); 81 static void configure(PropertyMapper &);
79 static void configure(IndexPropertyMapper &indexPropertyMapper); 82 static void configure(IndexPropertyMapper &indexPropertyMapper);
83 static QMap<QByteArray, int> typeDatabases();
80}; 84};
81 85
82template<> 86template<>
@@ -87,6 +91,7 @@ public:
87 static void configure(TypeIndex &); 91 static void configure(TypeIndex &);
88 static void configure(PropertyMapper &); 92 static void configure(PropertyMapper &);
89 static void configure(IndexPropertyMapper &indexPropertyMapper); 93 static void configure(IndexPropertyMapper &indexPropertyMapper);
94 static QMap<QByteArray, int> typeDatabases();
90}; 95};
91 96
92} 97}
diff --git a/common/domain/typeimplementations_p.h b/common/domain/typeimplementations_p.h
new file mode 100644
index 0000000..b7a78ac
--- /dev/null
+++ b/common/domain/typeimplementations_p.h
@@ -0,0 +1,154 @@
1/*
2 * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include "typeindex.h"
21#include <QMap>
22
23template <typename T, typename First>
24void mergeImpl(T &map, First f)
25{
26 for (auto it = f.constBegin(); it != f.constEnd(); it++) {
27 map.insert(it.key(), it.value());
28 }
29}
30
31template <typename T, typename First, typename ... Tail>
32void mergeImpl(T &map, First f, Tail ...maps)
33{
34 for (auto it = f.constBegin(); it != f.constEnd(); it++) {
35 map.insert(it.key(), it.value());
36 }
37 mergeImpl<T, Tail...>(map, maps...);
38}
39
40template <typename First, typename ... Tail>
41First merge(First f, Tail ...maps)
42{
43 First map;
44 mergeImpl(f, maps...);
45 return map;
46}
47
48template <typename Property>
49class ValueIndex
50{
51public:
52 static void configure(TypeIndex &index)
53 {
54 index.addProperty<Property>();
55 }
56
57 template <typename EntityType>
58 static QMap<QByteArray, int> databases()
59 {
60 return {{QByteArray{EntityType::name} +".index." + Property::name, 1}};
61 }
62};
63
64
65template <typename Property, typename SortProperty>
66class SortedIndex
67{
68public:
69 static void configure(TypeIndex &index)
70 {
71 index.addPropertyWithSorting<Property, SortProperty>();
72 }
73
74 template <typename EntityType>
75 static QMap<QByteArray, int> databases()
76 {
77 return {{QByteArray{EntityType::name} +".index." + Property::name + ".sort." + SortProperty::name, 1}};
78 }
79};
80
81template <typename Property, typename SecondaryProperty>
82class SecondaryIndex
83{
84public:
85 static void configure(TypeIndex &index)
86 {
87 index.addSecondaryProperty<Property, SecondaryProperty>();
88 }
89
90 template <typename EntityType>
91 static QMap<QByteArray, int> databases()
92 {
93 return {{QByteArray{EntityType::name} +".index." + Property::name + SecondaryProperty::name, 1}};
94 }
95};
96
97template <typename Property, typename SecondaryProperty, typename Indexer>
98class CustomSecondaryIndex
99{
100public:
101 static void configure(TypeIndex &index)
102 {
103 index.addSecondaryPropertyIndexer<Property, SecondaryProperty, Indexer>();
104 }
105
106 template <typename EntityType>
107 static QMap<QByteArray, int> databases()
108 {
109 return Indexer::databases();
110 }
111};
112
113template <typename EntityType, typename ... Indexes>
114class IndexConfig
115{
116 template <typename T>
117 static void applyIndex(TypeIndex &index)
118 {
119 T::configure(index);
120 }
121
122 ///Apply recursively for parameter pack
123 template <typename First, typename Second, typename ... Tail>
124 static void applyIndex(TypeIndex &index)
125 {
126 applyIndex<First>(index);
127 applyIndex<Second, Tail...>(index);
128 }
129
130 template <typename T>
131 static QMap<QByteArray, int> getDbs()
132 {
133 return T::template databases<EntityType>();
134 }
135
136 template <typename First, typename Second, typename ... Tail>
137 static QMap<QByteArray, int> getDbs()
138 {
139 return merge(getDbs<First>(), getDbs<Second, Tail...>());
140 }
141
142public:
143 static void configure(TypeIndex &index)
144 {
145 applyIndex<Indexes...>(index);
146 }
147
148 static QMap<QByteArray, int> databases()
149 {
150 return getDbs<Indexes...>();
151 }
152
153};
154
diff --git a/common/mail/threadindexer.cpp b/common/mail/threadindexer.cpp
index d91ab5f..af96b94 100644
--- a/common/mail/threadindexer.cpp
+++ b/common/mail/threadindexer.cpp
@@ -145,3 +145,10 @@ void ThreadIndexer::remove(const ApplicationDomain::ApplicationDomainType &entit
145 145
146} 146}
147 147
148QMap<QByteArray, int> ThreadIndexer::databases()
149{
150 return {{"mail.index.messageIdthreadId", 1},
151 {"mail.index.subjectthreadId", 1},
152 {"mail.index.threadIdmessageId", 1}};
153}
154
diff --git a/common/mail/threadindexer.h b/common/mail/threadindexer.h
index 064ae71..60d0863 100644
--- a/common/mail/threadindexer.h
+++ b/common/mail/threadindexer.h
@@ -29,6 +29,7 @@ public:
29 virtual void add(const ApplicationDomain::ApplicationDomainType &entity) Q_DECL_OVERRIDE; 29 virtual void add(const ApplicationDomain::ApplicationDomainType &entity) Q_DECL_OVERRIDE;
30 virtual void modify(const ApplicationDomain::ApplicationDomainType &old, const ApplicationDomain::ApplicationDomainType &entity) Q_DECL_OVERRIDE; 30 virtual void modify(const ApplicationDomain::ApplicationDomainType &old, const ApplicationDomain::ApplicationDomainType &entity) Q_DECL_OVERRIDE;
31 virtual void remove(const ApplicationDomain::ApplicationDomainType &entity) Q_DECL_OVERRIDE; 31 virtual void remove(const ApplicationDomain::ApplicationDomainType &entity) Q_DECL_OVERRIDE;
32 static QMap<QByteArray, int> databases();
32private: 33private:
33 void updateThreadingIndex(const QByteArray &identifier, const ApplicationDomain::ApplicationDomainType &entity, Sink::Storage::DataStore::Transaction &transaction); 34 void updateThreadingIndex(const QByteArray &identifier, const ApplicationDomain::ApplicationDomainType &entity, Sink::Storage::DataStore::Transaction &transaction);
34}; 35};
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 @@
36using namespace Sink; 36using namespace Sink;
37using namespace Sink::Storage; 37using namespace Sink::Storage;
38 38
39static QMap<QByteArray, int> baseDbs()
40{
41 return {{"revisionType", 0},
42 {"revisions", 0},
43 {"uids", 0},
44 {"default", 0},
45 {"__flagtable", 0}};
46}
47
48template <typename T, typename First>
49void 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
56template <typename T, typename First, typename ... Tail>
57void 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
65template <typename First, typename ... Tail>
66First merge(First f, Tail ...maps)
67{
68 First map;
69 mergeImpl(f, maps...);
70 return map;
71}
72
73template <class T>
74struct DbLayoutHelper {
75 void operator()(QMap<QByteArray, int> map) const {
76 mergeImpl(map, ApplicationDomain::TypeImplementation<T>::typeDatabases());
77 }
78};
79
39static Sink::Storage::DbLayout dbLayout(const QByteArray &instanceId) 80static 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