speedup annotation looksup

This commit is contained in:
j 2011-08-23 12:47:59 +02:00
parent 39f42aa1dd
commit a6e120322f
2 changed files with 9 additions and 7 deletions

View file

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

View file

@ -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'],