From: W. Trevor King Date: Thu, 12 May 2011 13:23:14 +0000 (-0400) Subject: Make BugDir._uuids_cache a set. X-Git-Tag: 1.1.0~192 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4920a709bc172ca65cf0f618226c3c2758697528;p=be.git 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. --- 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):