load sequences with raw sql

This commit is contained in:
j 2012-06-17 16:23:54 +02:00
parent 7f567d78a0
commit 9f4cdb1f63

View file

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