Skip to content

Commit

Permalink
Trans: Use SQL functions to migrate data
Browse files Browse the repository at this point in the history
That is way faster than doing that in Python
  • Loading branch information
nijel committed Jul 23, 2020
1 parent e2e2895 commit 378676e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions weblate/trans/migrations/0091_json_key.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by Django 3.0.7 on 2020-07-23 08:41

from django.db import migrations
from django.db.models import F
from django.db.models.functions import Substr


def report_progress(previous, current):
Expand All @@ -20,18 +22,10 @@ def migrate_componentlist(apps, schema_editor):
"i18next",
"webextension",
"json-nested",
)
),
context__startswith=".",
)
count = units.count()
if not count:
return
progress = -1
for pos, unit in enumerate(units.iterator()):
if unit.context.startswith("."):
unit.context = unit.context[1:]
unit.save(update_fields=["context"])
progress = report_progress(progress, 100 * pos // count)
report_progress(progress, 100)
units.update(context=Substr(F("context"), 2))


class Migration(migrations.Migration):
Expand Down

0 comments on commit 378676e

Please sign in to comment.