Go back to lazy bug loading to get execution speed back up.
authorW. Trevor King <wking@drexel.edu>
Sun, 23 Nov 2008 14:50:56 +0000 (09:50 -0500)
committerW. Trevor King <wking@drexel.edu>
Sun, 23 Nov 2008 14:50:56 +0000 (09:50 -0500)
Fixes bug b3c6da51-3a30-42c9-8c75-587c7a1705c5

19 files changed:
.be/bugs/b3c6da51-3a30-42c9-8c75-587c7a1705c5/values [new file with mode: 0644]
becommands/assign.py
becommands/close.py
becommands/comment.py
becommands/diff.py
becommands/list.py
becommands/new.py
becommands/open.py
becommands/remove.py
becommands/set.py
becommands/set_root.py
becommands/severity.py
becommands/show.py
becommands/status.py
becommands/target.py
libbe/bug.py
libbe/bugdir.py
libbe/comment.py
libbe/diff.py

diff --git a/.be/bugs/b3c6da51-3a30-42c9-8c75-587c7a1705c5/values b/.be/bugs/b3c6da51-3a30-42c9-8c75-587c7a1705c5/values
new file mode 100644 (file)
index 0000000..d1a7029
--- /dev/null
@@ -0,0 +1,35 @@
+
+
+
+creator=W. Trevor King <wking@drexel.edu>
+
+
+
+
+
+
+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
+
+
+
index 2cdcf4ce90028703e02cb1699fcb328113a04cea..b01c66a137cfea306f76c2e0c8472352d5a32a24 100644 (file)
@@ -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
index 38a5613787d626bcc31e9bdf78c34bbf2e579e25..67813f7943714f621dbdd0bbff24b30ac7ee5e87 100644 (file)
@@ -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()
index 045b33143bb047351aa034b8f1765fdc6e9c2f63..172f81896464f1e931a57b16e459cdfc6f70931f 100644 (file)
@@ -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
     <BLANKLINE>
-    >>> 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
     <BLANKLINE>
     """
@@ -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:
index 9d8d3b590a9d2f8e1980154c49ef3e4b5388c028..0a3bab187f6c3095692ccb6a460693e873cc7fea 100644 (file)
@@ -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:
index 22d73d92621eb1da636a46077585d3a6fbb444bc..63e1cd6750d94241eaaf55af9dee0678a00b3421 100644 (file)
@@ -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":
index c9688b9353482ed32ecb5ccde1889ec79992cb66..caa1549e13e46c3a65ffb6564d0a5c16d730d1e5 100644 (file)
@@ -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)
index 736b601167a065cfcd6597eb09e3178234faf2e5..788a183ed2a69a04122f5b42cb41fc515253f1a5 100644 (file)
@@ -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()
index 7ba5e23c4aad1082bd262479aee945973552a0a0..6fddb1f3293e57a0e76c3dfc92be05c28a66db91 100644 (file)
@@ -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()
index 7951c8beffcaf70b3dc3588c9aebbdf2b1b5ad7e..d556ea6f6ba5f8e5b67a29ddcf2eea010abd6d6a 100644 (file)
@@ -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()
index a2d2d954a1a0241d3706b03d1aa9f4a8789bc468..9fb48cbd3044ea1331c9f7e804339502c236b894 100644 (file)
@@ -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:
index d7df13dcb6f37b285ee8928a9a58b991e66a41d4..3f254453607d7bbe1b173e140ba681b701eb91a0 100644 (file)
@@ -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
index a2cd322136c00fc7bf36e4a84c7dc87721910f22..9e4e647cd869f430dee64d5f757ea2631ac25226 100644 (file)
@@ -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)
index de171f58141c6e1222b54e58dcf189c11af366f6..3dfd5485a67fd93643bf99c4608139e08f808b08 100644 (file)
@@ -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
index 2047397251ee1b22a4585dcd2620f3f2e94985bb..3ca7710ac73c829568cf43fb8c0d90023e278da9 100644 (file)
@@ -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:
index 6a9a58930847cb7b368d5c748715f428b13e9b6c..ef1629c9172af9af622fbe3f7862e6d7b669a4f9 100644 (file)
@@ -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)
index 2501a277b9b6296d03c25aea2b8721fa0b6300a1..779de6b87e0e104cdd91d98fc61a1b25a1d426b2 100644 (file)
@@ -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]
 
 
index 0bfc12d1c16094c4821a7a098d1ac7707df90098..9b87f1875deb1d4ff60928bbfd0781761725f355 100644 (file)
@@ -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:
index 470a864a845baac548fbc08274c118dcb1097644..f147bce05c2164635a61c128e3b5460870e035b1 100644 (file)
@@ -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: