Cache Bug.time by hand to avoid lots of redundant calls to str_to_time.
authorW. Trevor King <wking@drexel.edu>
Thu, 12 May 2011 12:41:25 +0000 (08:41 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 12 May 2011 12:52:47 +0000 (08:52 -0400)
libbe/bug.py

index 8b4b13064b06d547870cecd23d0d7f69b70e1d90..47e4b674debb388567f8dbb4a09206b14a559f0b 100644 (file)
@@ -194,10 +194,19 @@ class Bug (settings_object.SavedSettingsObject):
 
     def _get_time(self):
         if self.time_string == None:
+            self._cached_time_string = None
+            self._cached_time = None
             return None
-        return utility.str_to_time(self.time_string)
+        if (not hasattr(self, '_cached_time_string')
+            or self.time_string != self._cached_time_string):
+            self._cached_time_string = self.time_string
+            self._cached_time = utility.str_to_time(self.time_string)
+        return self._cached_time
     def _set_time(self, value):
-        self.time_string = utility.time_to_str(value)
+        if not hasattr(self, '_cached_time') or value != self._cached_time:
+            self.time_string = utility.time_to_str(value)
+            self._cached_time_string = self.time_string
+            self._cached_time = value
     time = property(fget=_get_time,
                     fset=_set_time,
                     doc="An integer version of .time_string")