From 701a53a665b132caa72ec4f04c6ff5d397578ae9 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Fri, 24 Jul 2015 17:19:44 +0100 Subject: [PATCH 2/2] Annotation.json: hard-code some field name mappings Not creating and indexing this dictionary afresh on every iteration makes fetching a test edit >10% faster. --- pandora/annotation/models.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 4b33961..6ca053c 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -216,17 +216,13 @@ class Annotation(models.Model): def json(self, layer=False, keys=None, user=None): j = { 'user': self.user.username, + 'id': self.public_id, + 'in': self.start, + 'out': self.end, + 'value': self.value, + 'created': self.created, + 'modified': self.modified, } - for key in ('id', 'in', 'out', 'value', 'created', 'modified'): - j[key] = getattr(self, { - 'hue': 'clip__hue', - 'id': 'public_id', - 'in': 'start', - 'lightness': 'clip__lightness', - 'out': 'end', - 'saturation': 'clip__saturation', - 'volume': 'clip__volume', - }.get(key, key)) j['duration'] = abs(j['out'] - j['in']) if user: j['editable'] = self.editable(user) -- 2.4.3