forked from 0x2620/pandora
load sequences with raw sql
This commit is contained in:
parent
7f567d78a0
commit
9f4cdb1f63
1 changed files with 26 additions and 10 deletions
|
@ -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():
|
||||
keys = None
|
||||
values = []
|
||||
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()
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue