From af0d87b569e85879cd71d29821269e6916d98588 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 19 Apr 2016 10:51:15 +0100 Subject: [PATCH] Annotation.json: reduce repeated layer lookups It's actually quite costly to look up keys in CONFIG, particularly inside a loop: this trims ~5% off get(keys=['layers']) for annotation-heavy items. --- pandora/annotation/models.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index a8ede67d..c274d28e 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -98,7 +98,7 @@ class Annotation(models.Model): value = models.TextField() findvalue = models.TextField(null=True) sortvalue = models.CharField(max_length=1000, null=True, blank=True, db_index=True) - + languages = models.CharField(max_length=255, null=True, blank=True) def editable(self, user): @@ -138,8 +138,7 @@ class Annotation(models.Model): findvalue = self.value try: - l = self.get_layer() - if l['type'] == 'entity': + if layer['type'] == 'entity': findvalue = self.get_entity().name except: pass @@ -232,7 +231,7 @@ class Annotation(models.Model): annotation_keys = ( 'id', 'in', 'out', 'value', 'created', 'modified', - 'duration', 'layer', 'item', 'videoRatio', 'languages', + 'duration', 'layer', 'item', 'videoRatio', 'languages', 'entity', 'event', 'place' ) _clip_keys = ('hue', 'lightness', 'saturation', 'volume') @@ -295,10 +294,10 @@ class Annotation(models.Model): value = getattr(self.item.sort, key) if value != None: j[key] = value - subtitles = get_by_key(settings.CONFIG['layers'], 'isSubtitles', True) - if subtitles: - if 'id' in j and self.layer == subtitles['id'] and not self.value: - del j['id'] + + if l.get('isSubtitles') and 'id' in j and not self.value: + del j['id'] + return j def __unicode__(self):