summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2014-01-16 17:33:20 -0400
committerKali Kaneko <kali@leap.se>2014-01-16 17:33:20 -0400
commit6c7207a5667d8158572b2a900a3506e3c3ecc6e5 (patch)
tree951497ce242b3ad165764c295fcd80fe4b253b82 /src
parenta660231e918df6698b6dcfad9d1845bd77ee6f8f (diff)
Temporal refactor setting of recent flag.
This flag is set way too often, and is damaging performance. Will move it to a single doc per mailbox in subsequente commits.
Diffstat (limited to 'src')
-rw-r--r--src/leap/mail/imap/mailbox.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py
index 137f9f5..cf09bc4 100644
--- a/src/leap/mail/imap/mailbox.py
+++ b/src/leap/mail/imap/mailbox.py
@@ -529,6 +529,10 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
messages_asked = self._bound_seq(messages_asked)
seq_messg = self._filter_msg_seq(messages_asked)
+ def getmsg(msgid):
+ if self.isWriteable():
+ deferLater(reactor, 2, self._unset_recent_flag, messages_asked)
+ return self.messages.get_msg_by_uid(msgid)
# for sequence numbers (uid = 0)
if sequence:
@@ -538,12 +542,6 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
else:
result = ((msgid, getmsg(msgid)) for msgid in seq_messg)
- if self.isWriteable():
- deferLater(reactor, 30, self._unset_recent_flag)
- # XXX I should rewrite the scheduler so it handles a
- # set of queues with different priority.
- self._unset_recent_flag()
-
# this should really be called as a final callback of
# the do_FETCH method...
deferLater(reactor, 1, self._signal_unread_to_ui)
@@ -594,7 +592,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
return result
@deferred
- def _unset_recent_flag(self):
+ def _unset_recent_flag(self, message_uid):
"""
Unsets `Recent` flag from a tuple of messages.
Called from fetch.
@@ -610,19 +608,16 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
If it is not possible to determine whether or not this
session is the first session to be notified about a message,
then that message SHOULD be considered recent.
- """
- # TODO this fucker, for the sake of correctness, is messing with
- # the whole collection of flag docs.
- # Possible ways of action:
- # 1. Ignore it, we want fun.
- # 2. Trigger it with a delay
- # 3. Route it through a queue with lesser priority than the
- # regularar writer.
+ :param message_uids: the sequence of msg ids to update.
+ :type message_uids: sequence
+ """
+ # XXX deprecate this!
+ # move to a mailbox-level call, and do it in batches!
- log.msg('unsetting recent flags...')
- for msg in self.messages.get_recent():
- msg.removeFlags((fields.RECENT_FLAG,))
+ log.msg('unsetting recent flag: %s' % message_uid)
+ msg = self.messages.get_msg_by_uid(message_uid)
+ msg.removeFlags((fields.RECENT_FLAG,))
self._signal_unread_to_ui()
@deferred
@@ -691,7 +686,9 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
msg.setFlags(flags)
result[msg_id] = msg.getFlags()
- self._signal_unread_to_ui()
+ # this should really be called as a final callback of
+ # the do_FETCH method...
+ deferLater(reactor, 1, self._signal_unread_to_ui)
return result
# ISearchableMailbox
@@ -758,6 +755,8 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
new_fdoc[self.MBOX_KEY] = self.mbox
d = self._do_add_doc(new_fdoc)
+ # XXX notify should be done when all the
+ # copies in the batch are finished.
d.addCallback(self._notify_new)
@deferred