diff options
author | mathieui <mathieui@mathieui.net> | 2013-05-11 20:51:11 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2013-05-11 20:51:11 +0200 |
commit | a1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4 (patch) | |
tree | e4c44c7e373101336d3ca04f8bcf882d3a3814f7 /src/roster.py | |
parent | cb61d5efaa5c500a376bbbbfee3e0b1381f73c93 (diff) | |
download | poezio-a1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4.tar.gz poezio-a1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4.tar.bz2 poezio-a1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4.tar.xz poezio-a1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4.zip |
Handle the roster order cache as a real cache
When an external (or internal) event may cause the order of the
cache to be modified, or new elements to be added, schedule it
for a rebuild. Otherwise, don’t, and only rebuild it when
refreshing (that should improve refresh speed a lot).
Also, if the position in the roster is further than the total size
of the roster, go back to the top instead of displaying an empty
window with “+++”.
Diffstat (limited to 'src/roster.py')
-rw-r--r-- | src/roster.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/roster.py b/src/roster.py index b0f3cf65..5ddbdbb2 100644 --- a/src/roster.py +++ b/src/roster.py @@ -17,6 +17,7 @@ from contact import Contact from roster_sorting import SORTING_METHODS, GROUP_SORTING_METHODS from os import path as p +from datetime import datetime from common import safeJID from sleekxmpp import JID from sleekxmpp.exceptions import IqError, IqTimeout @@ -43,6 +44,17 @@ class Roster(object): self.groups = {} self.contacts = {} + # Used for caching roster infos + self.last_built = datetime.now() + self.last_modified = datetime.now() + + def modified(self): + self.last_modified = datetime.now() + + @property + def needs_rebuild(self): + return self.last_modified >= self.last_built + def __getitem__(self, key): """Get a Contact from his bare JID""" key = safeJID(key).bare |