From ccd214ecb4d2852b907adc6126c0405955d1d45d Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 5 Feb 2014 13:50:23 +0000 Subject: [PATCH] limit clips in smart lists to 100, fix items for smart lists --- pandora/edit/models.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/pandora/edit/models.py b/pandora/edit/models.py index 1fcc429a..2a4204c1 100644 --- a/pandora/edit/models.py +++ b/pandora/edit/models.py @@ -198,14 +198,24 @@ class Edit(models.Model): def get_clips(self, user=None): if self.type == 'static': - clips = [c.json(user) for c in self.clips.all().order_by('index')] + clips = self.clips.all() else: - #FIXME: limit results!! - clips = [c.edit_json(user) for c in clip.models.Clip.objects.find(self.clip_query(), user)] - index = 0 - for c in clips: - c['index'] = index - index += 1 + clips = clip.models.Clip.objects.find(self.clip_query(), user) + return clips + + def get_clips_json(self, user=None): + qs = self.get_clips() + if self.type == 'static': + clips = [c.json(user) for c in qs.order_by('index')] + else: + if qs.count() <= 100: + clips = [c.edit_json(user) for c in qs] + index = 0 + for c in clips: + c['index'] = index + index += 1 + else: + clips = [] return clips def clip_query(self): @@ -299,13 +309,13 @@ class Edit(models.Model): 'posterFrames': 'poster_frames' } if 'clips' in keys or 'duration' in keys: - clips = self.get_clips(user) + clips = self.get_clips_json(user) for key in keys: if key == 'id': response[key] = self.get_id() elif key == 'items': - response[key] = self.clips.all().count() + response[key] = self.get_clips().count() elif key == 'query': if not self.query.get('static', False): response[key] = self.query