Klaus Demo klaus / c361ba5
Cache get_last_updated_at() method Refs #238 Jonas Haag 2 months ago
1 changed file(s) with 24 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
3030
3131 def get_last_updated_at(self):
3232 """Get datetime of last commit to this repository."""
33 refs = []
34 for ref_hash in self.get_refs().values():
35 try:
36 refs.append(self[ref_hash])
37 except KeyError:
38 # Whoops. The ref points at a non-existant object
39 pass
40 refs.sort(key=lambda obj:getattr(obj, 'commit_time', float('-inf')),
41 reverse=True)
42 for ref in refs:
43 # Find the latest ref that has a commit_time; tags do not
44 # have a commit time
45 if hasattr(ref, "commit_time"):
46 return ref.commit_time
47 return None
33 def _get_last_updated_at():
34 refs = []
35 for ref_hash in self.get_refs().values():
36 try:
37 refs.append(self[ref_hash])
38 except KeyError:
39 # Whoops. The ref points at a non-existant object
40 pass
41 refs.sort(key=lambda obj:getattr(obj, 'commit_time', float('-inf')),
42 reverse=True)
43 for ref in refs:
44 # Find the latest ref that has a commit_time; tags do not
45 # have a commit time
46 if hasattr(ref, "commit_time"):
47 return ref.commit_time
48 return None
49
50 # Cache result to speed up repo_list.html template.
51 # If self.refs.keys() as changed, we should invalidate the cache.
52 cache_key = self.refs.keys()
53 if cache_key != getattr(self, '_last_updated_at_cache_key', None):
54 self._last_updated_at_cache_retval = _get_last_updated_at()
55 self._last_updated_at_cache_key = cache_key
56 return self._last_updated_at_cache_retval
4857
4958 @property
5059 def cloneurl(self):