From 8cb776eb510b3a0454a8f03f394abe34c4014e2c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 10 Nov 2014 11:39:38 +0100 Subject: [PATCH] compute edit duration more efficiently --- pandora/edit/models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandora/edit/models.py b/pandora/edit/models.py index 561f9f87..09343516 100644 --- a/pandora/edit/models.py +++ b/pandora/edit/models.py @@ -316,7 +316,7 @@ class Edit(models.Model): _map = { 'posterFrames': 'poster_frames' } - if 'clips' in keys or 'duration' in keys: + if 'clips' in keys: clips = self.get_clips_json(user) for key in keys: @@ -330,7 +330,11 @@ class Edit(models.Model): elif key == 'clips': response[key] = clips elif key == 'duration': - response[key] = sum([c['duration'] for c in clips]) + if self.type == 'static': + response[key] = sum([(c['annotation__end'] or c['end']) - (c['annotation__start'] or c['start']) + for c in self.get_clips(user).values('start', 'end', 'annotation__start', 'annotation__end')]) + else: + response[key] = sum([c['end'] - c['start'] for c in self.get_clips(user).values('start', 'end')]) elif key == 'editable': response[key] = self.editable(user) elif key == 'user':