Skip to content
Snippets Groups Projects
Commit f861c67e authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Optimise DocumentLink creation in fixception migration

parent fc5f7dd7
No related branches found
No related tags found
1 merge request!18Transcription search
......@@ -10,6 +10,7 @@ def transcription_to_document(apps, schema_editor):
DocumentLink = apps.get_model('documents', 'DocumentLink')
nb = Transcription.objects.count()
last = 0
links = []
for i, ts in enumerate(Transcription.objects.all()):
percent = int(100.0 * (i + 1) / nb)
if percent % 5 == 0 and last != percent:
......@@ -21,7 +22,9 @@ def transcription_to_document(apps, schema_editor):
ts.save()
max_order_dl = DocumentLink.objects.filter(parent_id=ts.zone.document.id).order_by('-order').first()
order = 0 if max_order_dl is None else max_order_dl.order + 1
DocumentLink.objects.create(parent_id=ts.zone.document.id, child_id=doc.id, order=order)
links.append(DocumentLink(parent_id=ts.zone.document.id, child_id=doc.id, order=order))
print('Saving document links...')
DocumentLink.objects.bulk_create(links)
class Migration(migrations.Migration):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment