summaryrefslogtreecommitdiffstats
path: root/common/domain/mail.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-16 14:55:20 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-21 09:02:21 +0200
commit237b9ae4113e7a9f489632296941becb71afdb45 (patch)
tree01cde58f495944f01cad9d282391d4efd2897141 /common/domain/mail.cpp
parent95d11bf0be98a4e3c08502fe23417b800233ce14 (diff)
downloadsink-237b9ae4113e7a9f489632296941becb71afdb45.tar.gz
sink-237b9ae4113e7a9f489632296941becb71afdb45.zip
Refactor how the storage is used.
This is the initial refactoring to improve how we deal with the storage. It does a couple of things: * Rename Sink::Storage to Sink::Storage::DataStore to free up the Sink::Storage namespace * Introduce a Sink::ResourceContext to have a single object that can be passed around containing everything that is necessary to operate on a resource. This is a lot better than the multiple separate parameters that we used to pass around all over the place, while still allowing for dependency injection for tests. * Tie storage access together using the new EntityStore that directly works with ApplicationDomainTypes. This gives us a central place where main storage, indexes and buffer adaptors are tied together, which will also give us a place to implement external indexes, such as a fulltextindex using xapian. * Use ApplicationDomainTypes as the default way to pass around entities. Instead of using various ways to pass around entities (buffers, buffer adaptors, ApplicationDomainTypes), only use a single way. The old approach was confusing, and was only done as: * optimization; really shouldn't be necessary and otherwise I'm sure we can find better ways to optimize ApplicationDomainType itself. * a way to account for entities that have multiple buffers, a concept that I no longer deem relevant. While this commit does the bulk of the work to get there, the following commits will refactor more stuff to get things back to normal.
Diffstat (limited to 'common/domain/mail.cpp')
-rw-r--r--common/domain/mail.cpp52
1 files changed, 31 insertions, 21 deletions
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp
index 2b6eb84..1b46e28 100644
--- a/common/domain/mail.cpp
+++ b/common/domain/mail.cpp
@@ -45,25 +45,31 @@ static QMutex sMutex;
45using namespace Sink; 45using namespace Sink;
46using namespace Sink::ApplicationDomain; 46using namespace Sink::ApplicationDomain;
47 47
48void TypeImplementation<Mail>::configureIndex(TypeIndex &index)
49{
50 index.addProperty<QByteArray>(Mail::Uid::name);
51 index.addProperty<QByteArray>(Mail::Sender::name);
52 index.addProperty<QByteArray>(Mail::SenderName::name);
53 /* index->addProperty<QString>(Mail::Subject::name); */
54 /* index->addFulltextProperty<QString>(Mail::Subject::name); */
55 index.addProperty<QDateTime>(Mail::Date::name);
56 index.addProperty<QByteArray>(Mail::Folder::name);
57 index.addPropertyWithSorting<QByteArray, QDateTime>(Mail::Folder::name, Mail::Date::name);
58 index.addProperty<QByteArray>(Mail::MessageId::name);
59 index.addProperty<QByteArray>(Mail::ParentMessageId::name);
60
61 index.addProperty<Mail::MessageId>();
62 index.addSecondaryProperty<Mail::MessageId, Mail::ThreadId>();
63 index.addSecondaryProperty<Mail::ThreadId, Mail::MessageId>();
64}
65
48static TypeIndex &getIndex() 66static TypeIndex &getIndex()
49{ 67{
50 QMutexLocker locker(&sMutex); 68 QMutexLocker locker(&sMutex);
51 static TypeIndex *index = 0; 69 static TypeIndex *index = 0;
52 if (!index) { 70 if (!index) {
53 index = new TypeIndex("mail"); 71 index = new TypeIndex("mail");
54 index->addProperty<QByteArray>(Mail::Uid::name); 72 TypeImplementation<Mail>::configureIndex(*index);
55 index->addProperty<QByteArray>(Mail::Sender::name);
56 index->addProperty<QByteArray>(Mail::SenderName::name);
57 index->addProperty<QString>(Mail::Subject::name);
58 index->addProperty<QDateTime>(Mail::Date::name);
59 index->addProperty<QByteArray>(Mail::Folder::name);
60 index->addPropertyWithSorting<QByteArray, QDateTime>(Mail::Folder::name, Mail::Date::name);
61 index->addProperty<QByteArray>(Mail::MessageId::name);
62 index->addProperty<QByteArray>(Mail::ParentMessageId::name);
63
64 index->addProperty<Mail::MessageId>();
65 index->addSecondaryProperty<Mail::MessageId, Mail::ThreadId>();
66 index->addSecondaryProperty<Mail::ThreadId, Mail::MessageId>();
67 } 73 }
68 return *index; 74 return *index;
69} 75}
@@ -122,7 +128,7 @@ static QString stripOffPrefixes(const QString &subject)
122} 128}
123 129
124 130
125static void updateThreadingIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 131static void updateThreadingIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction)
126{ 132{
127 auto messageId = bufferAdaptor.getProperty(Mail::MessageId::name); 133 auto messageId = bufferAdaptor.getProperty(Mail::MessageId::name);
128 auto parentMessageId = bufferAdaptor.getProperty(Mail::ParentMessageId::name); 134 auto parentMessageId = bufferAdaptor.getProperty(Mail::ParentMessageId::name);
@@ -164,16 +170,17 @@ static void updateThreadingIndex(const QByteArray &identifier, const BufferAdapt
164 } 170 }
165} 171}
166 172
167void TypeImplementation<Mail>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 173void TypeImplementation<Mail>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction)
168{ 174{
169 SinkTrace() << "Indexing " << identifier; 175 SinkTrace() << "Indexing " << identifier;
170 getIndex().add(identifier, bufferAdaptor, transaction); 176 getIndex().add(identifier, bufferAdaptor, transaction);
171 updateThreadingIndex(identifier, bufferAdaptor, transaction); 177 updateThreadingIndex(identifier, bufferAdaptor, transaction);
172} 178}
173 179
174void TypeImplementation<Mail>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 180void TypeImplementation<Mail>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction)
175{ 181{
176 getIndex().remove(identifier, bufferAdaptor, transaction); 182 getIndex().remove(identifier, bufferAdaptor, transaction);
183 //TODO cleanup threading index
177} 184}
178 185
179QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper() 186QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplementation<Mail>::initializeReadPropertyMapper()
@@ -218,18 +225,21 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Mail>::BufferBuilder> > Ty
218} 225}
219 226
220 227
221DataStoreQuery::Ptr TypeImplementation<Mail>::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) 228DataStoreQuery::Ptr TypeImplementation<Mail>::prepareQuery(const Sink::Query &query, Sink::Storage::EntityStore::Ptr store)
222{ 229{
223 auto mapper = initializeReadPropertyMapper(); 230 auto mapper = initializeReadPropertyMapper();
224 return DataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName<Mail>(), transaction, getIndex(), [mapper, &transaction](const Sink::Entity &entity, const QByteArray &property) -> QVariant { 231 return DataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName<Mail>(), store, getIndex(), [mapper, store](const Sink::Entity &entity, const QByteArray &property) -> QVariant {
225 if (property == Mail::ThreadId::name) { 232 if (property == Mail::ThreadId::name) {
226 const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); 233 const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local());
227 Q_ASSERT(localBuffer); 234 Q_ASSERT(localBuffer);
228 auto messageId = mapper->getProperty(Mail::MessageId::name, localBuffer); 235 auto messageId = mapper->getProperty(Mail::MessageId::name, localBuffer);
236 //FIXME
229 //This is an index property that we have too lookup 237 //This is an index property that we have too lookup
230 auto thread = getIndex().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId, transaction); 238 /* auto thread = getIndex().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId); */
231 Q_ASSERT(!thread.isEmpty()); 239 /* auto thread = store->secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId); */
232 return thread.first(); 240 /* Q_ASSERT(!thread.isEmpty()); */
241 /* return thread.first(); */
242 return QVariant();
233 } else { 243 } else {
234 const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); 244 const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local());
235 Q_ASSERT(localBuffer); 245 Q_ASSERT(localBuffer);