slice update to reduce memory usage
This commit is contained in:
parent
40eed92b7a
commit
3947da68ba
1 changed files with 14 additions and 6 deletions
|
@ -29,12 +29,20 @@ 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):
|
||||||
for s in orm['sequence.Sequence'].objects.all():
|
while len(s) >= n:
|
||||||
s.mode2 = s.mode == 'color' and 1 or 0
|
yield s[:n]
|
||||||
s.hash2 = int(s.hash, 16) - 9223372036854775808
|
s = s[n:]
|
||||||
s.save()
|
if len(s):
|
||||||
|
yield s
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
def backwards(self, orm):
|
def backwards(self, orm):
|
||||||
# Removing unique constraint on 'Sequence', fields ['sort', 'start', 'end', 'mode']
|
# Removing unique constraint on 'Sequence', fields ['sort', 'start', 'end', 'mode']
|
||||||
|
|
Loading…
Reference in a new issue