From a1ef835a37f1d1dd4fb861ba4cc3919941bfb6e4 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 11 May 2013 20:51:11 +0200 Subject: Handle the roster order cache as a real cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 “+++”. --- src/roster.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/roster.py') 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 -- cgit v1.2.3