Commit b2765292 authored by Michal Čihař's avatar Michal Čihař

Optimize fetching last change data

Avoid using exception, we first figure out if object exists and then
fetch it including related user record (which we will need in most
cases anyway).

Issue #861
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 2846d8eb
......@@ -679,11 +679,15 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
@property
def last_change_obj(self):
"""Cached getter for last content change."""
if not self._last_change_obj_valid:
try:
self._last_change_obj = self.change_set.content()[0]
except IndexError:
changes = self.change_set.content()
if changes.exists():
self._last_change_obj = changes.select_related('author')[0]
else:
self._last_change_obj = None
self._last_change_obj_valid = True
return self._last_change_obj
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment