summaryrefslogtreecommitdiff
path: root/src/leap/mail/adaptors
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-03-26 15:59:33 -0400
committerKali Kaneko <kali@leap.se>2015-03-30 14:48:14 -0400
commit8e916eeadfcd76d50b54a2621d789e6a296dcce6 (patch)
tree7bb82a2ff750c5dd830201a2aa730e29eabf7168 /src/leap/mail/adaptors
parentd11c03d1126f1744789d107b0f9bd04fc8a2f50b (diff)
[bug] fix early append notification
There's a workaround for "slow" APPENDS to an inbox, and it is that we have a flag to allow returning early when JUST the mdoc (the meta-document) has been written. However, this was givin a problem when doing a FETCH right after an APPEND (with notify_just_mdoc=True) has been done. This commit fixes it by making the FETCH command first check if there's an ongoing pending write, and queueing itself right after the write queue has been completed. This fixes the testFullAppend regression. Releases: 0.4.0
Diffstat (limited to 'src/leap/mail/adaptors')
-rw-r--r--src/leap/mail/adaptors/soledad.py34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/leap/mail/adaptors/soledad.py b/src/leap/mail/adaptors/soledad.py
index 7a1a92d..b8e5fd4 100644
--- a/src/leap/mail/adaptors/soledad.py
+++ b/src/leap/mail/adaptors/soledad.py
@@ -491,7 +491,7 @@ class MessageWrapper(object):
for doc_id, cdoc in zip(self.mdoc.cdocs, self.cdocs.values()):
cdoc.set_future_doc_id(doc_id)
- def create(self, store, notify_just_mdoc=False):
+ def create(self, store, notify_just_mdoc=False, pending_inserts_dict=None):
"""
Create all the parts for this message in the store.
@@ -503,7 +503,7 @@ class MessageWrapper(object):
Be warned that in that case there will be no record of failures
when creating the other part-documents.
- Other-wise, this method will return a deferred that will wait for
+ Otherwise, this method will return a deferred that will wait for
the creation of all the part documents.
Setting this flag to True is mostly a convenient workaround for the
@@ -513,6 +513,9 @@ class MessageWrapper(object):
times will be enough to have all the queued insert operations
finished.
:type notify_just_mdoc: bool
+ :param pending_inserts_dict:
+ a dictionary with the pending inserts ids.
+ :type pending_inserts_dict: dict
:return: a deferred whose callback will be called when either all the
part documents have been written, or just the metamsg-doc,
@@ -527,26 +530,41 @@ class MessageWrapper(object):
leap_assert(self.fdoc.doc_id is None,
"Cannot create: fdoc has a doc_id")
+ def unblock_pending_insert(result):
+ msgid = self.hdoc.headers.get('Message-Id', None)
+ try:
+ d = pending_inserts_dict[msgid]
+ d.callback(msgid)
+ except KeyError:
+ pass
+ return result
+
# TODO check that the doc_ids in the mdoc are coherent
- d = []
+ self.d = []
+
mdoc_created = self.mdoc.create(store)
- d.append(mdoc_created)
- d.append(self.fdoc.create(store))
+ fdoc_created = self.fdoc.create(store)
+
+ self.d.append(mdoc_created)
+ self.d.append(fdoc_created)
if not self._is_copy:
if self.hdoc.doc_id is None:
- d.append(self.hdoc.create(store))
+ self.d.append(self.hdoc.create(store))
for cdoc in self.cdocs.values():
if cdoc.doc_id is not None:
# we could be just linking to an existing
# content-doc.
continue
- d.append(cdoc.create(store))
+ self.d.append(cdoc.create(store))
+
+ self.all_inserted_d = defer.gatherResults(self.d)
if notify_just_mdoc:
+ self.all_inserted_d.addCallback(unblock_pending_insert)
return mdoc_created
else:
- return defer.gatherResults(d)
+ return self.all_inserted_d
def update(self, store):
"""