Edit.json: preload annotation users
The expensive part of fetching an edit is JSONifying the clips' annotations. Profiling showed that the main cost was Annotation.json(), and within that: File: /srv/pandora/pandora/annotation/models.py Function: json at line 216 Line # Hits Time Per Hit % Time Line Contents ============================================================== 216 def json(self, layer=False, keys=None, user=None): 217 632 827 1.3 0.1 j = { 218 632 1048170 1658.5 89.6 'user': self.user.username, 219 } Obviously this join just moves some of the cost further out, but it brings my micro-benchmark down from 1.3s to 0.3s.
This commit is contained in:
parent
ab5a20d3a2
commit
f3fdded07d
1 changed files with 1 additions and 1 deletions
|
@ -522,7 +522,7 @@ class Clip(models.Model):
|
|||
if user and user.is_anonymous():
|
||||
user = None
|
||||
qs = qs.filter(user=user)
|
||||
for a in qs.order_by('start'):
|
||||
for a in qs.order_by('start').select_related('user'):
|
||||
ll.append(a.json(user=user))
|
||||
return layers
|
||||
|
||||
|
|
Loading…
Reference in a new issue