summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-10-22 17:07:47 +0200
committerDuda Dornelles <ddornell@thoughtworks.com>2014-10-23 12:08:31 +0200
commit64d87fd813d999de682b37b3e0b26df33762d338 (patch)
tree591d97c730de4681c49f9e0ad6244c9a85d1b270 /service
parentf43b9625e4bf04a4c03a8949c930d623eced02bd (diff)
#117 making partial fetch of all_mails more reliable in case the fdoc of a mail has already been synced but the hdoc hasnt - have to do the same for cdocs
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/mail.py2
-rw-r--r--service/pixelated/adapter/soledad_querier.py14
-rw-r--r--service/test/integration/soledad_querier_test.py13
3 files changed, 23 insertions, 6 deletions
diff --git a/service/pixelated/adapter/mail.py b/service/pixelated/adapter/mail.py
index ebdcf02b..f21ed2ef 100644
--- a/service/pixelated/adapter/mail.py
+++ b/service/pixelated/adapter/mail.py
@@ -99,7 +99,7 @@ class InputMail(Mail):
def ident(self):
return self._get_chash()
- def _get_for_save(self, next_uid, mailbox):
+ def get_for_save(self, next_uid, mailbox):
docs = [self._fdoc(next_uid, mailbox), self._hdoc()]
docs.extend([m for m in self._cdocs()])
return docs
diff --git a/service/pixelated/adapter/soledad_querier.py b/service/pixelated/adapter/soledad_querier.py
index ce75750a..796e8321 100644
--- a/service/pixelated/adapter/soledad_querier.py
+++ b/service/pixelated/adapter/soledad_querier.py
@@ -62,9 +62,15 @@ class SoledadQuerier:
if len(fdocs_chash) == 0:
return []
- fdocs_hdocs = [(f[0], self.soledad.get_from_index('by-type-and-contenthash', 'head', f[1])[0]) for f in fdocs_chash]
- fdocs_hdocs_phash = [(f[0], f[1], f[1].content.get('body')) for f in fdocs_hdocs]
- fdocs_hdocs_bdocs = [(f[0], f[1], self.soledad.get_from_index('by-type-and-payloadhash', 'cnt', f[2])[0]) for f in fdocs_hdocs_phash]
+ fdocs_hdocs = []
+ for fdoc, chash in fdocs_chash:
+ hdoc = self.soledad.get_from_index('by-type-and-contenthash', 'head', chash)
+ if len(hdoc) == 0:
+ continue
+ fdocs_hdocs.append((fdoc, hdoc[0]))
+
+ fdocs_hdocs_bodyphash = [(f[0], f[1], f[1].content.get('body')) for f in fdocs_hdocs]
+ fdocs_hdocs_bdocs = [(f[0], f[1], self.soledad.get_from_index('by-type-and-payloadhash', 'cnt', f[2])[0]) for f in fdocs_hdocs_bodyphash]
return [PixelatedMail.from_soledad(*raw_mail, soledad_querier=self) for raw_mail in fdocs_hdocs_bdocs]
def save_mail(self, mail):
@@ -77,7 +83,7 @@ class SoledadQuerier:
mbox = [m for m in self.soledad.get_from_index('by-type', 'mbox') if m.content['mbox'] == 'INBOX'][0]
uid = mbox.content['lastuid'] + 1
- new_docs = [self.soledad.create_doc(doc) for doc in mail._get_for_save(next_uid=uid, mailbox=mailbox_name)]
+ new_docs = [self.soledad.create_doc(doc) for doc in mail.get_for_save(next_uid=uid, mailbox=mailbox_name)]
mbox.content['lastuid'] = uid
self.soledad.put_doc(mbox)
diff --git a/service/test/integration/soledad_querier_test.py b/service/test/integration/soledad_querier_test.py
index 3c1ce6e1..a6d0319f 100644
--- a/service/test/integration/soledad_querier_test.py
+++ b/service/test/integration/soledad_querier_test.py
@@ -17,7 +17,7 @@
import copy
import unittest
import time
-from test.support.integration_helper import SoledadTestBase
+from test.support.integration_helper import SoledadTestBase, MailBuilder
from leap.mail.imap.fields import WithMsgFields
@@ -55,3 +55,14 @@ class SoledadQuerierTest(unittest.TestCase, SoledadTestBase, WithMsgFields):
inboxes = self._get_mailboxes_from_soledad('INBOX')
self.assertEqual(1, len(inboxes))
self.assertEqual(3, inboxes[0].content['lastuid'])
+
+ def test_all_mails_skips_incomplete_mails(self):
+ self.add_multiple_to_mailbox(1, 'INBOX')
+ self.add_multiple_to_mailbox(1, 'SENT')
+
+ # creating incomplete mail, we will only save the fdoc
+ fdoc, hdoc, bdoc = MailBuilder().build_input_mail().get_for_save(2, 'INBOX')
+
+ self.soledad.create_doc(fdoc)
+ mails = self.soledad_querier.all_mails()
+ self.assertEqual(2, len(mails)) # mail is incomplete since it only has fdoc \ No newline at end of file