slice update to reduce memory usage

This commit is contained in:
j 2013-03-06 09:52:39 +00:00
parent 40eed92b7a
commit 3947da68ba

View file

@ -30,8 +30,16 @@ class Migration(SchemaMigration):
# Adding unique constraint on 'Sequence', fields ['sort', 'start', 'end', 'mode'] # Adding unique constraint on 'Sequence', fields ['sort', 'start', 'end', 'mode']
db.create_unique('sequence_sequence', ['sort_id', 'start', 'end', 'mode']) db.create_unique('sequence_sequence', ['sort_id', 'start', 'end', 'mode'])
def nslice(s, n):
while len(s) >= n:
yield s[:n]
s = s[n:]
if len(s):
yield s
for s in orm['sequence.Sequence'].objects.all(): ids = [s['id'] for s in orm['sequence.Sequence'].objects.all().values('id')]
for i in nslice(ids, 10000):
for s in orm['sequence.Sequence'].objects.filter(id__in=i):
s.mode2 = s.mode == 'color' and 1 or 0 s.mode2 = s.mode == 'color' and 1 or 0
s.hash2 = int(s.hash, 16) - 9223372036854775808 s.hash2 = int(s.hash, 16) - 9223372036854775808
s.save() s.save()