slice update to reduce memory usage
This commit is contained in:
parent
40eed92b7a
commit
3947da68ba
1 changed files with 14 additions and 6 deletions
|
@ -30,8 +30,16 @@ class Migration(SchemaMigration):
|
|||
# Adding unique constraint on 'Sequence', fields ['sort', '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.hash2 = int(s.hash, 16) - 9223372036854775808
|
||||
s.save()
|
||||
|
|
Loading…
Reference in a new issue