wrap adding many clips in transaction, should be faster

This commit is contained in:
j 2014-02-09 11:30:40 +00:00
parent 545710528e
commit 58e787efd7

View file

@ -48,14 +48,15 @@ def addClips(request):
clips = [] clips = []
if edit.editable(request.user): if edit.editable(request.user):
index = data.get('index', edit.clips.count()) index = data.get('index', edit.clips.count())
for c in data['clips']: with transaction.commit_on_success():
clip = edit.add_clip(c, index) for c in data['clips']:
index += 1 clip = edit.add_clip(c, index)
if not clip: index += 1
response = json_response(status=500, text='invalid in/out') if not clip:
return render_to_json_response(response) response = json_response(status=500, text='invalid in/out')
else: return render_to_json_response(response)
clips.append(clip.json(request.user)) else:
clips.append(clip.json(request.user))
response['data']['clips'] = clips response['data']['clips'] = clips
else: else:
response = json_response(status=403, text='permission denied') response = json_response(status=403, text='permission denied')
@ -253,12 +254,13 @@ def addEdit(request):
if 'clips' in data and edit.type == 'static': if 'clips' in data and edit.type == 'static':
index = 0 index = 0
for c in data['clips']: with transaction.commit_on_success():
clip = edit.add_clip(c, index) for c in data['clips']:
index += 1 clip = edit.add_clip(c, index)
if not clip: index += 1
response = json_response(status=500, text='invalid in/out') if not clip:
return render_to_json_response(response) response = json_response(status=500, text='invalid in/out')
return render_to_json_response(response)
if edit.status == 'featured': if edit.status == 'featured':
pos, created = models.Position.objects.get_or_create(edit=edit, pos, created = models.Position.objects.get_or_create(edit=edit,