diff options
author | W. Trevor King <wking@drexel.edu> | 2008-11-23 09:50:56 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2008-11-23 09:50:56 -0500 |
commit | 510c9f33393c1f222ee56732c026f229ed8ae49d (patch) | |
tree | ba51973a3fd3eb5893d413f6c8b5a721867d26dc /libbe | |
parent | 333fc7968794deff9aa7a7a91d72cf17763df855 (diff) | |
download | bugseverywhere-510c9f33393c1f222ee56732c026f229ed8ae49d.tar.gz |
Go back to lazy bug loading to get execution speed back up.
Fixes bug b3c6da51-3a30-42c9-8c75-587c7a1705c5
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/bug.py | 28 | ||||
-rw-r--r-- | libbe/bugdir.py | 42 | ||||
-rw-r--r-- | libbe/comment.py | 14 | ||||
-rw-r--r-- | libbe/diff.py | 16 |
4 files changed, 62 insertions, 38 deletions
diff --git a/libbe/bug.py b/libbe/bug.py index 6a9a589..ef1629c 100644 --- a/libbe/bug.py +++ b/libbe/bug.py @@ -95,17 +95,20 @@ class Bug(object): active = property(_get_active) - def __init__(self, bugdir=None, uuid=None, loadNow=False, summary=None): + def __init__(self, bugdir=None, uuid=None, from_disk=False, + load_comments=False, summary=None): self.bugdir = bugdir if bugdir != None: self.rcs = bugdir.rcs else: self.rcs = None - if loadNow == True: + if from_disk == True: + self._comments_loaded = False self.uuid = uuid - self.load() + self.load(load_comments=load_comments) else: # Note: defaults should match those in Bug.load() + self._comments_loaded = True if uuid != None: self.uuid = uuid else: @@ -162,6 +165,8 @@ class Bug(object): bugout = "%s:%s: %s" % (shortname, chars, self.summary.rstrip('\n')) if show_comments == True: + if self._comments_loaded == False: + self.load_comments() comout = self.comment_root.string_thread(auto_name_map=True, bug_shortname=shortname) output = bugout + '\n' + comout.rstrip('\n') @@ -182,7 +187,7 @@ class Bug(object): assert name in ["values", "comments"] return os.path.join(my_dir, name) - def load(self): + def load(self, load_comments=False): map = mapfile.map_load(self.get_path("values")) self.summary = map.get("summary") self.creator = map.get("creator") @@ -193,8 +198,13 @@ class Bug(object): self.time = map.get("time") if self.time is not None: self.time = utility.str_to_time(self.time) - + + if load_comments == True: + self.load_comments() + + def load_comments(self): self.comment_root = comment.loadComments(self) + self._comments_loaded = True def _add_attr(self, map, name): value = getattr(self, name) @@ -217,11 +227,13 @@ class Bug(object): path = self.get_path("values") mapfile.map_save(self.rcs, path, map) - if len(self.comment_root) > 0: - self.rcs.mkdir(self.get_path("comments")) - comment.saveComments(self) + if self._comments_loaded: + if len(self.comment_root) > 0: + self.rcs.mkdir(self.get_path("comments")) + comment.saveComments(self) def remove(self): + self.load_comments() self.comment_root.remove() path = self.get_path() self.rcs.recursive_remove(path) diff --git a/libbe/bugdir.py b/libbe/bugdir.py index 2501a27..779de6b 100644 --- a/libbe/bugdir.py +++ b/libbe/bugdir.py @@ -89,11 +89,11 @@ class BugDir (list): be flushed to the file system automatically. However, the BugDir will only load information from the file system when it loads new bugs/comments that it doesn't already have in memory, or when it - explicitly asked to do so (e.g. .load() or __init__(loadNow=True)). + explicitly asked to do so (e.g. .load() or __init__(from_disk=True)). """ def __init__(self, root=None, sink_to_existing_root=True, assert_new_BugDir=False, allow_rcs_init=False, - loadNow=False, rcs=None): + from_disk=False, rcs=None): list.__init__(self) self._save_user_id = False self.settings = {} @@ -105,7 +105,7 @@ class BugDir (list): if not os.path.exists(root): raise NoRootEntry(root) self.root = root - if loadNow == True: + if from_disk == True: self.load() else: if assert_new_BugDir == True: @@ -217,15 +217,17 @@ class BugDir (list): self.settings = self._get_settings(self.get_path("settings")) self.rcs = rcs_by_name(self.rcs_name) - if self._user_id != None: # there was a user name in the settings file - self.save_user_id() - - self._clear_bugs() - for uuid in self.list_uuids(): - self._load_bug(uuid) + if self._user_id != None: # was a user name in the settings file + self.save_user_id() self._bug_map_gen() + def load_all_bugs(self): + "Warning: this could take a while." + self._clear_bugs() + for uuid in self.list_uuids(): + self._load_bug(uuid) + def save(self): self.rcs.mkdir(self.get_path()) self.set_version() @@ -274,7 +276,7 @@ class BugDir (list): duplicate_settings["user-id"] = self.user_id self._save_settings(duplicate_settings_path, duplicate_settings) - return BugDir(duplicate_path, loadNow=True) + return BugDir(duplicate_path, from_disk=True) def remove_duplicate_bugdir(self): self.rcs.remove_duplicate_repo() @@ -283,6 +285,9 @@ class BugDir (list): map = {} for bug in self: map[bug.uuid] = bug + for uuid in self.list_uuids(): + if uuid not in map: + map[uuid] = None self.bug_map = map def list_uuids(self): @@ -304,7 +309,7 @@ class BugDir (list): self.pop() def _load_bug(self, uuid): - bg = bug.Bug(bugdir=self, uuid=uuid, loadNow=True) + bg = bug.Bug(bugdir=self, uuid=uuid, from_disk=True) self.append(bg) self._bug_map_gen() return bg @@ -347,14 +352,15 @@ class BugDir (list): a:om: Bug A """ matches = [] - for bug in self: - if bug.uuid.startswith(shortname): - matches.append(bug) + self._bug_map_gen() + for uuid in self.bug_map.keys(): + if uuid.startswith(shortname): + matches.append(uuid) if len(matches) > 1: - raise cmdutil.UserError("More than one bug matches %s. Please be more" - " specific." % shortname) + raise cmdutil.UserError("More than one bug matches %s. " + "Please be more specific." % shortname) if len(matches) == 1: - return matches[0] + return self.bug_from_uuid(matches[0]) raise KeyError("No bug matches %s" % shortname) def bug_from_uuid(self, uuid): @@ -362,6 +368,8 @@ class BugDir (list): self._bug_map_gen() if uuid not in self.bug_map: raise KeyError("No bug matches %s" % uuid +str(self.bug_map)+str(self)) + if self.bug_map[uuid] == None: + self._load_bug(uuid) return self.bug_map[uuid] diff --git a/libbe/comment.py b/libbe/comment.py index 0bfc12d..9b87f18 100644 --- a/libbe/comment.py +++ b/libbe/comment.py @@ -63,7 +63,7 @@ def loadComments(bug): for uuid in os.listdir(path): if uuid.startswith('.'): continue - comm = Comment(bug, uuid, loadNow=True) + comm = Comment(bug, uuid, from_disk=True) comments.append(comm) return _list_to_root(comments, bug) @@ -74,16 +74,16 @@ def saveComments(bug): comment.save() class Comment(Tree): - def __init__(self, bug=None, uuid=None, loadNow=False, + def __init__(self, bug=None, uuid=None, from_disk=False, in_reply_to=None, body=None): """ - Set loadNow=True to load an old bug. - Set loadNow=False to create a new bug. + Set from_disk=True to load an old bug. + Set from_disk=False to create a new bug. - The uuid option is required when loadNow==True. + The uuid option is required when from_disk==True. The in_reply_to and body options are only used if - loadNow==False (the default). When loadNow==True, they are + from_disk==False (the default). When from_disk==True, they are loaded from the bug database. in_reply_to should be the uuid string of the parent comment. @@ -94,7 +94,7 @@ class Comment(Tree): self.rcs = bug.rcs else: self.rcs = None - if loadNow == True: + if from_disk == True: self.uuid = uuid self.load() else: diff --git a/libbe/diff.py b/libbe/diff.py index 470a864..f147bce 100644 --- a/libbe/diff.py +++ b/libbe/diff.py @@ -24,15 +24,17 @@ def diff(old_bugdir, new_bugdir): added = [] removed = [] modified = [] - for old_bug in old_bugdir: - new_bug = new_bugdir.bug_map.get(old_bug.uuid) - if new_bug is None : - removed.append(old_bug) - else: + for uuid in old_bugdir.list_uuids(): + old_bug = old_bugdir.bug_from_uuid(uuid) + try: + new_bug = new_bugdir.bug_from_uuid(uuid) if old_bug != new_bug: modified.append((old_bug, new_bug)) - for new_bug in new_bugdir: + except KeyError: + removed.append(old_bug) + for uuid in new_bugdir.list_uuids(): if not old_bugdir.bug_map.has_key(new_bug.uuid): + new_bug = new_bugdir.bug_from_uuid(uuid) added.append(new_bug) return (removed, modified, added) @@ -82,7 +84,9 @@ def bug_changes(old, new, bugs): change_list = change_lines(old, new, ("time", "creator", "severity", "target", "summary", "status", "assigned")) + old.load_comments() old_comment_ids = [c.uuid for c in old.comment_root.traverse()] + new.load_comments() new_comment_ids = [c.uuid for c in new.comment_root.traverse()] change_strings = ["%s: %s -> %s" % f for f in change_list] for comment_id in new_comment_ids: |