summaryrefslogtreecommitdiff
path: root/mail/src/leap
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2014-02-04 15:39:52 -0400
committerKali Kaneko <kali@leap.se>2014-02-04 15:39:52 -0400
commit3d4f2123166c8e57ce2c9dfc57f52b91525cf316 (patch)
tree64162e50eaef8e5d6894bfc86f839c7da42ada2f /mail/src/leap
parenta6fa032552d119eafbd7a9338a3a90b5b31b07ac (diff)
Rebased dreb's commit to update sizes dictionary
for faster calculation of sizes. https://github.com/andrejb/leap_mail/commit/8b88e85fab3c2b75da16b16c8d492c001b8076c6
Diffstat (limited to 'mail/src/leap')
-rw-r--r--mail/src/leap/mail/imap/memorystore.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/mail/src/leap/mail/imap/memorystore.py b/mail/src/leap/mail/imap/memorystore.py
index 195cef79..a99148f3 100644
--- a/mail/src/leap/mail/imap/memorystore.py
+++ b/mail/src/leap/mail/imap/memorystore.py
@@ -106,6 +106,12 @@ class MemoryStore(object):
# Internal Storage: messages
self._msg_store = {}
+ # Sizes
+ """
+ {'mbox, uid': <int>}
+ """
+ self._sizes = {}
+
# Internal Storage: payload-hash
"""
{'phash': weakreaf.proxy(dict)}
@@ -347,8 +353,12 @@ class MemoryStore(object):
for key in seq:
if key in store and empty(store.get(key)):
store.pop(key)
+
prune((FDOC, HDOC, CDOCS, DOCS_ID), store)
+ # Update memory store size
+ self._sizes[key] = size(self._msg_store[key])
+
def get_docid_for_fdoc(self, mbox, uid):
"""
Return Soledad document id for the flags-doc for a given mbox and uid,
@@ -417,6 +427,9 @@ class MemoryStore(object):
self._new.discard(key)
self._dirty.discard(key)
self._msg_store.pop(key, None)
+ if key in self._sizes:
+ del self._sizes[key]
+
except Exception as exc:
logger.exception(exc)
@@ -958,4 +971,4 @@ class MemoryStore(object):
:rtype: int
"""
- return size.get_size(self._msg_store)
+ return reduce(lambda x, y: x + y, self._sizes, 0)