From 9f4cdb1f63e39f5b6ce059aff84c02472a5ad77b Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 17 Jun 2012 16:23:54 +0200 Subject: [PATCH] load sequences with raw sql --- pandora/sequence/tasks.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/pandora/sequence/tasks.py b/pandora/sequence/tasks.py index 0fd6614e2..a1ff5fd43 100644 --- a/pandora/sequence/tasks.py +++ b/pandora/sequence/tasks.py @@ -21,16 +21,32 @@ def get_sequences(itemId): position = 0 for stream in i.streams(): data, position = extract.get_sequences(stream.timeline_prefix, position) - with transaction.commit_on_success(): - for mode in data: - for seq in data[mode]: - s = models.Sequence() - s.item = i - s.mode = mode - s.start = float('%0.03f' % seq['in']) - s.end = float('%0.03f' % seq['out']) - s.hash = seq['hash'] - s.save() + keys = None + values = [] + for mode in data: + for s in data[mode]: + sequence = { + 'item_id': i.pk, + 'sort_id': i.sort.pk, + 'mode': mode, + 'start': float('%0.03f' % s['in']), + 'end': float('%0.03f' % s['out']), + 'hash': s['hash'] + } + sequence['public_id'] = u"%s/%0.03f-%0.03f" % ( + i.itemId, sequence['start'], sequence['end'] + ) + sequence['duration'] = sequence['end'] - sequence['start'] + if not keys: + keys = ', '.join(['"%s"'%k for k in sequence.keys()]) + v = ', '.join([isinstance(v, basestring) and "'%s'"%v or str(v) + for v in sequence.values()]) + values.append('(%s)'%v) + + cursor = connection.cursor() + sql = "INSERT INTO sequence_sequence (%s) VALUES %s" % (keys, ', '.join(values)); + cursor.execute(sql) + transaction.commit_unless_managed() @task(ignore_results=True, queue='encoding') def update_sequence_ids(itemId):