diff options
author | W. Trevor King <wking@drexel.edu> | 2011-05-12 09:23:14 -0400 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2011-05-12 09:23:19 -0400 |
commit | 4920a709bc172ca65cf0f618226c3c2758697528 (patch) | |
tree | 46604dbd4bcfa2e61d1f42acd7511c19271a9e01 /libbe/bugdir.py | |
parent | b3a21311f816a6f5ac91c1d7b94868e42ad42c1c (diff) | |
download | bugseverywhere-4920a709bc172ca65cf0f618226c3c2758697528.tar.gz |
Make BugDir._uuids_cache a set.
For `be list` on a bugdir with 4096 open bugs, this reduced the
cumulative time spend in 8194 calls to BugDir.uuids() from 41 seconds
to 33 seconds.
Of the 33 cumulative seconds, 24 were spend in uuids() itself (and not
in child functions), which is probably from the list comprehension
extracting in-memory Bug uuids. With fancier accounting, you could
probably trust _uuids_cache to already contain all the in-memory
uuids and dispense with the union altogether.
Diffstat (limited to 'libbe/bugdir.py')
-rw-r--r-- | libbe/bugdir.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/libbe/bugdir.py b/libbe/bugdir.py index 9741239..c73e097 100644 --- a/libbe/bugdir.py +++ b/libbe/bugdir.py @@ -220,14 +220,18 @@ class BugDir (list, settings_object.SavedSettingsObject): def uuids(self, use_cached_disk_uuids=True): if use_cached_disk_uuids==False or not hasattr(self, '_uuids_cache'): - self._uuids_cache = [] - # list bugs that are in storage - if self.storage != None and self.storage.is_readable(): - child_uuids = libbe.util.id.child_uuids( - self.storage.children(self.id.storage())) - for id in child_uuids: - self._uuids_cache.append(id) - return list(set([bug.uuid for bug in self] + self._uuids_cache)) + self._refresh_uuid_cache() + self._uuids_cache = self._uuids_cache.union([bug.uuid for bug in self]) + return self._uuids_cache + + def _refresh_uuid_cache(self): + self._uuids_cache = set() + # list bugs that are in storage + if self.storage != None and self.storage.is_readable(): + child_uuids = libbe.util.id.child_uuids( + self.storage.children(self.id.storage())) + for id in child_uuids: + self._uuids_cache.add(id) def _clear_bugs(self): while len(self) > 0: @@ -248,7 +252,7 @@ class BugDir (list, settings_object.SavedSettingsObject): self.append(bg) self._bug_map_gen() if hasattr(self, '_uuids_cache') and not bg.uuid in self._uuids_cache: - self._uuids_cache.append(bg.uuid) + self._uuids_cache.add(bg.uuid) return bg def remove_bug(self, bug): |