diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/mail/imap/mailbox.py | 22 | ||||
-rw-r--r-- | src/leap/mail/imap/memorystore.py | 17 | ||||
-rw-r--r-- | src/leap/mail/imap/messages.py | 14 |
3 files changed, 36 insertions, 17 deletions
diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py index c188f91..6e472ee 100644 --- a/src/leap/mail/imap/mailbox.py +++ b/src/leap/mail/imap/mailbox.py @@ -824,12 +824,12 @@ class SoledadMailbox(WithMsgFields, MBoxParser): memstore = self._memstore def createCopy(result): - exist, new_fdoc, hdoc = result + exist, new_fdoc = result if exist: # Should we signal error on the callback? logger.warning("Destination message already exists!") - # XXX I'm still not clear if we should raise the + # XXX I'm not sure if we should raise the # errback. This actually rases an ugly warning # in some muas like thunderbird. I guess the user does # not deserve that. @@ -848,8 +848,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser): self._memstore.create_message( self.mbox, uid_next, - MessageWrapper( - new_fdoc, hdoc), + MessageWrapper(new_fdoc), observer=observer, notify_on_disk=False) @@ -862,6 +861,9 @@ class SoledadMailbox(WithMsgFields, MBoxParser): """ Get a copy of the fdoc for this message, and check whether it already exists. + + :return: exist, new_fdoc + :rtype: tuple """ # XXX for clarity, this could be delegated to a # MessageCollection mixin that implements copy too, and @@ -869,22 +871,16 @@ class SoledadMailbox(WithMsgFields, MBoxParser): msg = message memstore = self._memstore - # XXX should use a public api instead - fdoc = msg._fdoc - hdoc = msg._hdoc - if not fdoc: + if empty(msg.fdoc): logger.warning("Tried to copy a MSG with no fdoc") return - new_fdoc = copy.deepcopy(fdoc.content) - copy_hdoc = copy.deepcopy(hdoc.content) + new_fdoc = copy.deepcopy(msg.fdoc.content) fdoc_chash = new_fdoc[fields.CONTENT_HASH_KEY] - # XXX is this hitting the db??? --- probably. - # We should profile after the pre-fetch. dest_fdoc = memstore.get_fdoc_from_chash( fdoc_chash, self.mbox) exist = dest_fdoc and not empty(dest_fdoc.content) - return exist, new_fdoc, copy_hdoc + return exist, new_fdoc # convenience fun diff --git a/src/leap/mail/imap/memorystore.py b/src/leap/mail/imap/memorystore.py index b198e12..4156c0b 100644 --- a/src/leap/mail/imap/memorystore.py +++ b/src/leap/mail/imap/memorystore.py @@ -592,7 +592,8 @@ class MemoryStore(object): :param mbox: the mailbox :type mbox: str or unicode - :param flag_docs: a dict with the content for the flag docs. + :param flag_docs: a dict with the content for the flag docs, indexed + by uid. :type flag_docs: dict """ # We can do direct assignments cause we know this will only @@ -601,6 +602,20 @@ class MemoryStore(object): for uid in flag_docs: fdoc_store[uid] = ReferenciableDict(flag_docs[uid]) + def load_header_docs(self, header_docs): + """ + Load the flag documents for the given mbox. + Used during header docs prefetch, and during cache after + a read from soledad if the hdoc property in message did not + find its value in here. + + :param flag_docs: a dict with the content for the flag docs. + :type flag_docs: dict + """ + hdoc_store = self._hdoc_store + for chash in header_docs: + hdoc_store[chash] = ReferenciableDict(header_docs[chash]) + def all_flags(self, mbox): """ Return a dictionary with all the flags for a given mbox. diff --git a/src/leap/mail/imap/messages.py b/src/leap/mail/imap/messages.py index fbae05f..4b95689 100644 --- a/src/leap/mail/imap/messages.py +++ b/src/leap/mail/imap/messages.py @@ -153,12 +153,20 @@ class LeapMessage(fields, MailParser, MBoxParser): """ An accessor to the headers document. """ - if self._container is not None: + container = self._container + if container is not None: hdoc = self._container.hdoc if hdoc and not empty(hdoc.content): return hdoc - # XXX cache this into the memory store !!! - return self._get_headers_doc() + hdoc = self._get_headers_doc() + + if container and not empty(hdoc.content): + # mem-cache it + hdoc_content = hdoc.content + chash = hdoc_content.get(fields.CONTENT_HASH_KEY) + hdocs = {chash: hdoc_content} + container.memstore.load_header_docs(hdocs) + return hdoc @property def chash(self): |