From: Michael Tremer Date: Tue, 10 Oct 2017 13:13:17 +0000 (+0100) Subject: bugzilla: Cache repsonses X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cc05687f46556046c7e66f9daa0852a0fab5566a;p=people%2Fjschlag%2Fpbs.git bugzilla: Cache repsonses 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 --- diff --git a/src/buildservice/bugtracker.py b/src/buildservice/bugtracker.py index 2832544..7dd4f67 100644 --- a/src/buildservice/bugtracker.py +++ b/src/buildservice/bugtracker.py @@ -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)