From: W. Trevor King Date: Sun, 23 Nov 2008 14:50:56 +0000 (-0500) Subject: Go back to lazy bug loading to get execution speed back up. X-Git-Tag: 1.0.0~123 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=510c9f33393c1f222ee56732c026f229ed8ae49d;p=be.git Go back to lazy bug loading to get execution speed back up. Fixes bug b3c6da51-3a30-42c9-8c75-587c7a1705c5 --- diff --git a/.be/bugs/b3c6da51-3a30-42c9-8c75-587c7a1705c5/values b/.be/bugs/b3c6da51-3a30-42c9-8c75-587c7a1705c5/values new file mode 100644 index 0000000..d1a7029 --- /dev/null +++ b/.be/bugs/b3c6da51-3a30-42c9-8c75-587c7a1705c5/values @@ -0,0 +1,35 @@ + + + +creator=W. Trevor King + + + + + + +severity=critical + + + + + + +status=fixed + + + + + + +summary=Slow be commands due to bugdir loading, go back to lazy bug loading. + + + + + + +time=Sun, 23 Nov 2008 13:48:01 +0000 + + + diff --git a/becommands/assign.py b/becommands/assign.py index 2cdcf4c..b01c66a 100644 --- a/becommands/assign.py +++ b/becommands/assign.py @@ -27,17 +27,17 @@ def execute(args): True >>> execute(["a"]) - >>> bd.load() - >>> bd.bug_from_shortname("a").assigned == bd.rcs.get_user_id() + >>> bd._clear_bugs() + >>> bd.bug_from_shortname("a").assigned == bd.user_id True >>> execute(["a", "someone"]) - >>> bd.load() + >>> bd._clear_bugs() >>> print bd.bug_from_shortname("a").assigned someone >>> execute(["a","none"]) - >>> bd.load() + >>> bd._clear_bugs() >>> bd.bug_from_shortname("a").assigned is None True """ @@ -48,10 +48,10 @@ def execute(args): if len(args) > 2: help() raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) bug = bd.bug_from_shortname(args[0]) if len(args) == 1: - bug.assigned = bug.rcs.get_user_id() + bug.assigned = bd.user_id elif len(args) == 2: if args[1] == "none": bug.assigned = None diff --git a/becommands/close.py b/becommands/close.py index 38a5613..67813f7 100644 --- a/becommands/close.py +++ b/becommands/close.py @@ -27,7 +27,7 @@ def execute(args): >>> print bd.bug_from_shortname("a").status open >>> execute(["a"]) - >>> bd.load() + >>> bd._clear_bugs() >>> print bd.bug_from_shortname("a").status closed """ @@ -37,7 +37,7 @@ def execute(args): if len(args) > 1: help() raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) bug = bd.bug_from_shortname(args[0]) bug.status = "closed" bd.save() diff --git a/becommands/comment.py b/becommands/comment.py index 045b331..172f818 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -25,12 +25,14 @@ def execute(args): >>> bd = bugdir.simple_bug_dir() >>> os.chdir(bd.root) >>> execute(["a", "This is a comment about a"]) - >>> bd.load() - >>> comment = bd.bug_from_shortname("a").comment_root[0] + >>> bd._clear_bugs() + >>> bug = bd.bug_from_shortname("a") + >>> bug.load_comments() + >>> comment = bug.comment_root[0] >>> print comment.body This is a comment about a - >>> comment.From == bd.rcs.get_user_id() + >>> comment.From == bd.user_id True >>> comment.time <= int(time.time()) True @@ -45,8 +47,11 @@ def execute(args): >>> os.environ["EDITOR"] = "echo 'I like cheese' > " >>> execute(["b"]) - >>> bd.load() - >>> print bd.bug_from_shortname("b").comment_root[0].body + >>> bd._clear_bugs() + >>> bug = bd.bug_from_shortname("b") + >>> bug.load_comments() + >>> comment = bug.comment_root[0] + >>> print comment.body I like cheese """ @@ -68,8 +73,9 @@ def execute(args): bugname = shortname is_reply = False - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) bug = bd.bug_from_shortname(bugname) + bug.load_comments() if is_reply: parent = bug.comment_root.comment_from_shortname(shortname, bug_shortname=bugname) else: diff --git a/becommands/diff.py b/becommands/diff.py index 9d8d3b5..0a3bab1 100644 --- a/becommands/diff.py +++ b/becommands/diff.py @@ -46,7 +46,7 @@ def execute(args): if len(args) > 1: help() raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) if bd.rcs.versioned == False: print "This directory is not revision-controlled." else: diff --git a/becommands/list.py b/becommands/list.py index 22d73d9..63e1cd6 100644 --- a/becommands/list.py +++ b/becommands/list.py @@ -36,7 +36,8 @@ def execute(args): if len(args) > 0: help() raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) + bd.load_all_bugs() # select status if options.status != None: if options.status == "all": @@ -84,7 +85,7 @@ def execute(args): assigned = "all" for i in range(len(assigned)): if assigned[i] == '-': - assigned[i] = bd.rcs.get_user_id() + assigned[i] = bd.user_id # select target if options.target != None: if options.target == "all": diff --git a/becommands/new.py b/becommands/new.py index c9688b9..caa1549 100644 --- a/becommands/new.py +++ b/becommands/new.py @@ -41,7 +41,7 @@ def execute(args): options, args = get_parser().parse_args(args) if len(args) != 1: raise cmdutil.UserError("Please supply a summary message") - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) bug = bd.new_bug(summary=args[0]) bd.save() print "Created bug with ID %s" % bd.bug_shortname(bug) diff --git a/becommands/open.py b/becommands/open.py index 736b601..788a183 100644 --- a/becommands/open.py +++ b/becommands/open.py @@ -26,7 +26,7 @@ def execute(args): >>> print bd.bug_from_shortname("b").status closed >>> execute(["b"]) - >>> bd.load() + >>> bd._clear_bugs() >>> print bd.bug_from_shortname("b").status open """ @@ -36,7 +36,7 @@ def execute(args): if len(args) > 1: help() raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) bug = bd.bug_from_shortname(args[0]) bug.status = "open" bd.save() diff --git a/becommands/remove.py b/becommands/remove.py index 7ba5e23..6fddb1f 100644 --- a/becommands/remove.py +++ b/becommands/remove.py @@ -28,7 +28,7 @@ def execute(args): closed >>> execute (["b"]) Removed bug b - >>> bd.load() + >>> bd._clear_bugs() >>> try: ... bd.bug_from_shortname("b") ... except KeyError: @@ -38,7 +38,7 @@ def execute(args): options, args = get_parser().parse_args(args) if len(args) != 1: raise cmdutil.UserError("Please specify a bug id.") - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) bug = bd.bug_from_shortname(args[0]) bd.remove_bug(bug) bd.save() diff --git a/becommands/set.py b/becommands/set.py index 7951c8b..d556ea6 100644 --- a/becommands/set.py +++ b/becommands/set.py @@ -36,7 +36,7 @@ def execute(args): if len(args) > 2: help() raise cmdutil.UserError("Too many arguments.") - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) if len(args) == 0: keys = bd.settings.keys() keys.sort() diff --git a/becommands/set_root.py b/becommands/set_root.py index a2d2d95..9fb48cb 100644 --- a/becommands/set_root.py +++ b/becommands/set_root.py @@ -67,7 +67,7 @@ def execute(args): pass #raise cmdutil.UserError, "No such directory: %s" % basedir try: - bd = bugdir.BugDir(basedir, loadNow=False, sink_to_existing_root=False, assert_new_BugDir=True) + bd = bugdir.BugDir(basedir, from_disk=False, sink_to_existing_root=False, assert_new_BugDir=True) except bugdir.NoRootEntry: raise cmdutil.UserError("No such directory: %s" % basedir) except bugdir.AlreadyInitialized: diff --git a/becommands/severity.py b/becommands/severity.py index d7df13d..3f25445 100644 --- a/becommands/severity.py +++ b/becommands/severity.py @@ -37,7 +37,7 @@ def execute(args): if len(args) not in (1,2): print help() return - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) bug = bd.bug_from_shortname(args[0]) if len(args) == 1: print bug.severity diff --git a/becommands/show.py b/becommands/show.py index a2cd322..9e4e647 100644 --- a/becommands/show.py +++ b/becommands/show.py @@ -38,7 +38,7 @@ def execute(args): options, args = get_parser().parse_args(args) if len(args) == 0: raise cmdutil.UserError("Please specify a bug id.") - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) for bugid in args: bug = bd.bug_from_shortname(bugid) print bug.string(show_comments=True) diff --git a/becommands/status.py b/becommands/status.py index de171f5..3dfd548 100644 --- a/becommands/status.py +++ b/becommands/status.py @@ -37,7 +37,7 @@ def execute(args): if len(args) not in (1,2): print help() return - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) bug = bd.bug_from_shortname(args[0]) if len(args) == 1: print bug.status diff --git a/becommands/target.py b/becommands/target.py index 2047397..3ca7710 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -37,7 +37,7 @@ def execute(args): if len(args) == 0: print help() return - bd = bugdir.BugDir(loadNow=True) + bd = bugdir.BugDir(from_disk=True) bug = bd.bug_from_shortname(args[0]) if len(args) == 1: if bug.target is None: 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: