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 position = 0
for stream in i.streams(): for stream in i.streams():
data, position = extract.get_sequences(stream.timeline_prefix, position) data, position = extract.get_sequences(stream.timeline_prefix, position)
with transaction.commit_on_success(): keys = None
for mode in data: values = []
for seq in data[mode]: for mode in data:
s = models.Sequence() for s in data[mode]:
s.item = i sequence = {
s.mode = mode 'item_id': i.pk,
s.start = float('%0.03f' % seq['in']) 'sort_id': i.sort.pk,
s.end = float('%0.03f' % seq['out']) 'mode': mode,
s.hash = seq['hash'] 'start': float('%0.03f' % s['in']),
s.save() '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') @task(ignore_results=True, queue='encoding')
def update_sequence_ids(itemId): def update_sequence_ids(itemId):