summaryrefslogtreecommitdiff
path: root/mail
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2014-02-13 11:42:06 -0400
committerKali Kaneko <kali@leap.se>2014-02-17 11:39:50 -0400
commit16eb2e1b99ed25efcce682ee5f1f5bb1936498e0 (patch)
treeffd958fe1343b4bc05d37d2fb52fddc9f9734a0f /mail
parent61f3c56ba7c86e686b1671f675569e21b0c6bc44 (diff)
avoid hitting db on every select
Diffstat (limited to 'mail')
-rw-r--r--mail/src/leap/mail/imap/account.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/mail/src/leap/mail/imap/account.py b/mail/src/leap/mail/imap/account.py
index 04af3b1..fd35698 100644
--- a/mail/src/leap/mail/imap/account.py
+++ b/mail/src/leap/mail/imap/account.py
@@ -18,6 +18,7 @@
Soledad Backed Account.
"""
import copy
+import logging
import time
from twisted.mail import imap4
@@ -30,6 +31,8 @@ from leap.mail.imap.parser import MBoxParser
from leap.mail.imap.mailbox import SoledadMailbox
from leap.soledad.client import Soledad
+logger = logging.getLogger(__name__)
+
#######################################
# Soledad Account
@@ -77,10 +80,13 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
self._soledad = soledad
self._memstore = memstore
+ self.__mailboxes = set([])
+
self.initialize_db()
# every user should have the right to an inbox folder
# at least, so let's make one!
+ self._load_mailboxes()
if not self.mailboxes:
self.addMailbox(self.INBOX_NAME)
@@ -112,9 +118,13 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
"""
A list of the current mailboxes for this account.
"""
- return [doc.content[self.MBOX_KEY]
- for doc in self._soledad.get_from_index(
- self.TYPE_IDX, self.MBOX_KEY)]
+ return self.__mailboxes
+
+ def _load_mailboxes(self):
+ self.__mailboxes.update(
+ [doc.content[self.MBOX_KEY]
+ for doc in self._soledad.get_from_index(
+ self.TYPE_IDX, self.MBOX_KEY)])
@property
def subscriptions(self):
@@ -179,6 +189,7 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
mbox[self.CREATED_KEY] = creation_ts
doc = self._soledad.create_doc(mbox)
+ self._load_mailboxes()
return bool(doc)
def create(self, pathspec):
@@ -209,6 +220,7 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
except imap4.MailboxCollision:
if not pathspec.endswith('/'):
return False
+ self._load_mailboxes()
return True
def select(self, name, readwrite=1):
@@ -221,13 +233,13 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
:param readwrite: 1 for readwrite permissions.
:type readwrite: int
- :rtype: bool
+ :rtype: SoledadMailbox
"""
name = self._parse_mailbox_name(name)
if name not in self.mailboxes:
+ logger.warning("No such mailbox!")
return None
-
self.selected = name
return SoledadMailbox(
@@ -266,6 +278,7 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
"Hierarchically inferior mailboxes "
"exist and \\Noselect is set")
mbox.destroy()
+ self._load_mailboxes()
# XXX FIXME --- not honoring the inferior names...
@@ -303,6 +316,8 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB, MBoxParser):
mbox.content[self.MBOX_KEY] = new
self._soledad.put_doc(mbox)
+ self._load_mailboxes()
+
# XXX ---- FIXME!!!! ------------------------------------
# until here we just renamed the index...
# We have to rename also the occurrence of this