Author: tmckay
Date: 2011-08-01 13:39:46 +0000 (Mon, 01 Aug 2011)
New Revision: 4897
Modified:
trunk/sage/python/sage/wallaby/wallabyoperations.py
Log:
Cache the tag list instead of generating on demand.
Modified: trunk/sage/python/sage/wallaby/wallabyoperations.py
===================================================================
--- trunk/sage/python/sage/wallaby/wallabyoperations.py 2011-07-29 20:05:00 UTC (rev
4896)
+++ trunk/sage/python/sage/wallaby/wallabyoperations.py 2011-08-01 13:39:46 UTC (rev
4897)
@@ -69,6 +69,11 @@
self._cache = {WBTypes.NODES: self.CacheData(refresh_interval),
WBTypes.GROUPS: self.CacheData(refresh_interval)}
+ # Tags are special. They are just a subset of groups, but it
+ # takes time to filter the list so it is handled in a separate
+ # thread when group data is received.
+ self._tags = []
+
# Lock is used for synchronization with the caching thread and
# for thread safety of any and all data that could be accessed
# by multiple threads.
@@ -268,27 +273,14 @@
define valid values for "which"
'''
d = []
- if which == WBTypes.TAGS:
- # Tags are special for the time being.
- # Tags are defined as non-internal groups with no parameters.
- # Get groups and filter.
- target = WBTypes.GROUPS
- else:
- target = which
-
- if target in self._cache:
- self._lock.acquire()
- d = self._cache[target].data
- self._lock.release()
-
- if which == WBTypes.TAGS:
- groups = d
- d = []
- for g in groups:
- if g.getConfig() == {} and not g.name.startswith("+++"):
- d.append(g)
+ self._lock.acquire()
+ if which in self._cache:
+ d = self._cache[which].data
+ elif which == WBTypes.TAGS:
+ d = self._tags
+ self._lock.release()
return d
-
+
def set_interval(self, which, refresh):
'''
Set an individual refresh interval for a data item.
@@ -333,6 +325,27 @@
self._lock.release()
log.debug("WallabyOperations: %s list updated (%s items)" % (attr,
len(data)))
+ # Filter groups for the subset of tags
+ if attr == WBTypes.GROUPS:
+ self._get_tag_list(data)
+
+ def _get_tag_list(self, data):
+
+ def process_tags(groups):
+ d = []
+ for g in groups:
+ if g.getConfig() == {} and not g.name.startswith("+++"):
+ d.append(g)
+ self._store_tag_list(d)
+
+ t = CallThread(process_tags, None, data)
+ t.start()
+
+ def _store_tag_list(self, tags):
+ self._lock.acquire()
+ self._tags = tags
+ self._lock.release()
+
def _get_store(self):
# Ideally there should only be a single Store object from a single agent.
# We constrain the search a bit, hopefully more efficient
Show replies by date