From a6e120322fb93f34be148b40625133e4644a8785 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 23 Aug 2011 12:47:59 +0200 Subject: [PATCH] speedup annotation looksup --- pandora/annotation/models.py | 14 ++++++++------ pandora/annotation/views.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 5bc06919..d2d127d3 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -79,8 +79,9 @@ class Annotation(models.Model): user = models.ForeignKey(User) item = models.ForeignKey('item.Item', related_name='annotations') + public_id = models.CharField(max_length=128, unique=True) #seconds - start = models.FloatField(default=-1) + start = models.FloatField(default=-1, db_index=True) end = models.FloatField(default=-1) layer = models.ForeignKey(Layer) @@ -100,12 +101,15 @@ class Annotation(models.Model): else: return self.value - def get_id(self): - return '%s/%s' % (self.item.itemId, ox.to32(self.id)) + def save(self, *args, **kwargs): + if not self.id: + super(Annotation, self).save(*args, **kwargs) + self.public_id = '%s/%s' % (self.item.itemId, ox.to32(self.id)) + super(Annotation, self).save(*args, **kwargs) def json(self, layer=False, keys=None): j = { - 'id': self.get_id(), + 'id': self.public_id, 'user': self.user.username, 'in': self.start, 'out': self.end, @@ -125,8 +129,6 @@ class Annotation(models.Model): streams = self.item.streams() if streams: j['videoRatio'] = streams[0].aspect_ratio - if 'item' in keys: - j['item'] = self.item.itemId return j def __unicode__(self): diff --git a/pandora/annotation/views.py b/pandora/annotation/views.py index e37aa6f0..11056fba 100644 --- a/pandora/annotation/views.py +++ b/pandora/annotation/views.py @@ -58,7 +58,7 @@ def findAnnotations(request): qs = qs[query['range'][0]:query['range'][1]] response['data']['items'] = [p.json(keys=data['keys']) for p in qs] elif 'position' in query: - ids = [i.get_id() for i in qs] + ids = [i.public_id for i in qs] data['conditions'] = data['conditions'] + { 'value': data['position'], 'key': query['sort'][0]['key'],