]> git.ipfire.org Git - people/jschlag/pbs.git/commitdiff
bugzilla: Cache repsonses
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 10 Oct 2017 13:13:17 +0000 (14:13 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 10 Oct 2017 13:13:17 +0000 (14:13 +0100)
Bugzilla is rather slow and we can just cache the status
of a bug to speed up page rendering

Fixes #11504

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/bugtracker.py

index 2832544ecec4a1085752e21a402e9803dc54db7e..7dd4f6754e4b92ee58435c781318cb7735c42dfe 100644 (file)
@@ -4,6 +4,8 @@ import xmlrpclib
 
 from . import base
 
+from .decorators import *
+
 class BugzillaBug(base.Object):
        def __init__(self, bugzilla, bug_id):
                base.Object.__init__(self, bugzilla.pakfire)
@@ -24,13 +26,25 @@ class BugzillaBug(base.Object):
        def id(self):
                return self.bug_id
 
-       @property
+       @lazy_property
        def data(self):
-               if self._data is None:
-                       self._data = self.call("get", ids=[self.id,])["bugs"][0]
-                       assert self._data
+               # Fetch bug information from cache
+               data = self.backend.cache.get(self._cache_key)
+
+               # Hit
+               if data:
+                       return data
+
+               # Fetch bug information from Bugzilla
+               for data in self.call("get", ids=[self.id,])["bugs"]:
+                       # Put it into the cache
+                       self.backend.cache.set(self._cache_key, data, self.backend.bugzilla.cache_lifetime)
 
-               return self._data
+                       return data
+
+       @property
+       def _cache_key(self):
+               return "bug-%s" % self.bug_id
 
        @property
        def url(self):
@@ -65,6 +79,9 @@ class BugzillaBug(base.Object):
 
                self.call("update", ids=[self.id,], **kwargs)
 
+               # Invalidate cache
+               self.backend.cache.delete(self.cache_key)
+
 
 class Bugzilla(base.Object):
        def __init__(self, pakfire):
@@ -129,6 +146,10 @@ class Bugzilla(base.Object):
        def password(self):
                return self.settings.get("bugzilla_xmlrpc_password")
 
+       @lazy_property
+       def cache_lifetime(self):
+               return self.settings.get("bugzilla_cache_lifetime", 3600)
+
        def get_bug(self, bug_id):
                try:
                        bug = BugzillaBug(self, bug_id)