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.
This commit is contained in:
Will Thompson 2016-04-19 10:51:15 +01:00
parent 3f5be0bd27
commit af0d87b569
No known key found for this signature in database
GPG key ID: 3422DC0D7AD482A7

View file

@ -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
@ -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):