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
values = []
for mode in data: for mode in data:
for seq in data[mode]: for s in data[mode]:
s = models.Sequence() sequence = {
s.item = i 'item_id': i.pk,
s.mode = mode 'sort_id': i.sort.pk,
s.start = float('%0.03f' % seq['in']) 'mode': mode,
s.end = float('%0.03f' % seq['out']) 'start': float('%0.03f' % s['in']),
s.hash = seq['hash'] 'end': float('%0.03f' % s['out']),
s.save() '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):