Combine {Item,Clip,edit.Clip}.get_layers()
This has several benefits:
• Clip.get_layers() (used by smart edits) and Item.get_layers() pick up
the select_related('user') optimization added for static edits in
r5007.
• Static edits and items pick up the optimization from r4941 to select
annotations once, not once per layer.
Fetching an item with ~1000 annotations took ~1s without this patch,
~0.34s with this patch. Another item with ~6000 annotations took ~11.6s
before, ~8.6s after.
Because this block is moved out to the top:
if user and user.is_anonymous():
user = None
then, for anonymous users,
"editable": false,
is no longer included in the annotations. The old behaviour ended up
including this key in all layers listed before the first private layer
in the config, and leaving it out from later ones. So this new behaviour
is more consistent.
This commit is contained in:
parent
861be871d5
commit
eebb0b5681
3 changed files with 36 additions and 53 deletions
|
|
@ -511,22 +511,8 @@ class Clip(models.Model):
|
|||
start = self.start
|
||||
end = self.end
|
||||
item = self.item
|
||||
layers = {}
|
||||
for l in settings.CONFIG['layers']:
|
||||
name = l['id']
|
||||
ll = layers.setdefault(name, [])
|
||||
qs = Annotation.objects.filter(layer=name, item=item).order_by(
|
||||
'start', 'end', 'sortvalue')
|
||||
if name == 'subtitles':
|
||||
qs = qs.exclude(value='')
|
||||
qs = qs.filter(start__lt=end, end__gt=start)
|
||||
if l.get('private'):
|
||||
if user and user.is_anonymous():
|
||||
user = None
|
||||
qs = qs.filter(user=user)
|
||||
for a in qs.order_by('start').select_related('user'):
|
||||
ll.append(a.json(user=user))
|
||||
return layers
|
||||
|
||||
return clip.models.get_layers(item=item, interval=(start, end), user=user)
|
||||
|
||||
class Position(models.Model):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue