def id(self):
return self.bug_id
- @property
- def cache_id(self):
- return "bug_%s" % self.id
-
- def clear_cache(self):
- self.cache.delete(self.cache_id)
-
@property
def data(self):
if self._data is None:
- data = self.cache.get(self.cache_id)
- if not data:
- data = self.call("get", ids=[self.id,])["bugs"][0]
- self.cache.set(self.cache_id, data, 120)
+ self._data = self.call("get", ids=[self.id,])["bugs"][0]
+ assert self._data
- self._data = data
return self._data
@property
kwargs["comment"] = { "body" : comment }
self.call("update", ids=[self.id,], **kwargs)
- self.clear_cache()
return bug
def find_users(self, pattern):
- users = self.cache.get("users_%s" % pattern)
- if users is None:
- users = self.call("User", "get", match=[pattern,])
- users = users["users"]
-
- self.cache.set("users_%s" % pattern, users)
-
- return users
+ users = self.call("User", "get", match=[pattern,])
+ if users:
+ return users["users"]
def find_user(self, pattern):
users = self.find_users(pattern)
return builds
def count(self):
- count = self.cache.get("builds_count")
- if count is None:
- builds = self.db.get("SELECT COUNT(*) AS count FROM builds")
-
- count = builds.count
- self.cache.set("builds_count", count, 3600 / 4)
-
- return count
+ builds = self.db.get("SELECT COUNT(*) AS count FROM builds")
+ if builds:
+ return builds.count
def needs_test(self, threshold, arch, limit=None, randomize=False):
query = "SELECT id FROM builds \
return cmp(self.pkg, other.pkg)
- @property
- def cache_key(self):
- return "build_%s" % self.id
-
- def clear_cache(self):
- """
- Clear the stored data from the cache.
- """
- self.cache.delete(self.cache_key)
-
@classmethod
def create(cls, pakfire, pkg, type="release", owner=None, distro=None, public=True):
assert type in ("release", "scratch", "test")
# Delete the build itself.
self.db.execute("DELETE FROM builds WHERE id = %s", self.id)
- self.clear_cache()
def __delete_bugs(self):
"""
Lazy fetching of data for this object.
"""
if self._data is None:
- data = self.cache.get(self.cache_key)
- if not data:
- # Fetch the whole row in one call.
- data = self.db.get("SELECT * FROM builds WHERE id = %s", self.id)
- self.cache.set(self.cache_key, data)
-
- self._data = data
+ self._data = self.db.get("SELECT * FROM builds WHERE id = %s", self.id)
assert self._data
return self._data
def set_depends_on(self, build):
self.db.execute("UPDATE builds SET depends_on = %s WHERE id = %s",
build.id, self.id)
- self.clear_cache()
# Update cache.
self._depends_on = build
if self._data:
self._data["severity"] = severity
- self.clear_cache()
def get_severity(self):
return self.data.severity
if self._data:
self._data["message"] = msg
- self.clear_cache()
def has_perm(self, user):
"""
self.db.execute("UPDATE builds SET priority = %s WHERE id = %s", priority,
self.id)
- self.clear_cache()
if self._data:
self._data["priority"] = priority
Returns the average build time of all finished builds from the
last 3 months.
"""
- cache_key = "jobs_avg_build_time"
-
- build_time = self.cache.get(cache_key)
- if not build_time:
- result = self.db.get("SELECT AVG(time_finished - time_started) as average \
- FROM jobs WHERE type = 'build' AND state = 'finished' AND \
- time_finished >= DATE_SUB(NOW(), INTERVAL 3 MONTH)")
+ result = self.db.get("SELECT AVG(time_finished - time_started) as average \
+ FROM jobs WHERE type = 'build' AND state = 'finished' AND \
+ time_finished >= DATE_SUB(NOW(), INTERVAL 3 MONTH)")
- build_time = result.average or 0
- self.cache.set(cache_key, build_time, 3600)
-
- return build_time
+ if result:
+ return result.average
def count(self, *states):
- states = sorted(states)
-
- cache_key = "jobs_count_%s" % ("-".join(states) or "all")
-
- count = self.cache.get(cache_key)
- if count is None:
- query = "SELECT COUNT(*) AS count FROM jobs"
- args = []
-
- if states:
- query += " WHERE %s" % " OR ".join("state = %s" for s in states)
- args += states
-
- jobs = self.db.get(query, *args)
+ query = "SELECT COUNT(*) AS count FROM jobs"
+ args = []
- count = jobs.count
- self.cache.set(cache_key, count, 60)
+ if states:
+ query += " WHERE state IN %s"
+ args.append(states)
- return count
+ jobs = self.db.get(query, *args)
+ if jobs:
+ return jobs.count
def get_queue_length(self):
res = self.db.get("SELECT COUNT(*) AS count FROM jobs_queue")
assert self.build.distro
return self.build.distro
- @property
- def cache_key(self):
- return "job_%s" % self.id
-
- def clear_cache(self):
- """
- Clear the stored data from the cache.
- """
- self.cache.delete(self.cache_key)
-
@classmethod
def create(cls, pakfire, build, arch, type="build"):
id = pakfire.db.execute("INSERT INTO jobs(uuid, type, build_id, arch_id, time_created) \
# Delete the job itself.
self.db.execute("DELETE FROM jobs WHERE id = %s", self.id)
- self.clear_cache()
def __delete_buildroots(self):
"""
# Nothing to do if the state remains.
if not self.state == state:
self.db.execute("UPDATE jobs SET state = %s WHERE id = %s", state, self.id)
- self.clear_cache()
# Log the event.
if log and not state == "new":
def update_message(self, msg):
self.db.execute("UPDATE jobs SET message = %s WHERE id = %s",
msg, self.id)
- self.clear_cache()
if self._data:
self._data["message"] = msg
# Update cache.
if self._data:
self._data["builder_id"] = builder.id
- self.clear_cache()
self._builder = builder
def set_aborted_state(self, state):
self.db.execute("UPDATE jobs SET aborted_state = %s WHERE id = %s",
state, self.id)
- self.clear_cache()
if self._data:
self._data["aborted_state"] = state
def __init__(self, pakfire):
base.Object.__init__(self, pakfire)
- # Private cache.
- self._cache = cache.PermanentCache(self.pakfire)
-
def query(self, key):
return self.db.get("SELECT * FROM settings WHERE k = %s", key)
- def get(self, key, default=None, cacheable=True):
- if cacheable and self.cache.has_key(key):
- return self.cache.get(key)
-
+ def get(self, key, default=None):
result = self.query(key)
if not result:
return default
- result = result.v
-
- # Put the item into the cache to access it later.
- if cacheable:
- self.cache.set(key, result)
-
- return result
+ return result.v
def get_id(self, key):
- return self.query(key)["id"]
+ res = self.query(key)
+
+ if res:
+ return res.id
- def get_int(self, key, default=None, cacheable=True):
- value = self.get(key, default, cacheable=cacheable)
+ def get_int(self, key, default=None):
+ value = self.get(key, default)
if value is None:
return None
return int(value)
- def get_float(self, key, default=None, cacheable=True):
- value = self.get(key, default, cacheable=cacheable)
+ def get_float(self, key, default=None):
+ value = self.get(key, default)
if value is None:
return None