Skip to content

Commit f5342d5

Browse files
perf: Improve performance for migration (#2898)
* improve performance for migration * increase iterator chunk_size for migration * fix error applying migration 0031_update_schema_after_pyxform_upgrade fix TypeError: UseMaster.__call__() missing 1 required positional argument: 'func' * update log message for migration * refactor to use use_master decorator * unpin migration to master db migrations are run against the default db, hence the use_master decorator is unnecessary * fix typo * catch TypeError when regenerating XForm schema from file
1 parent 11730d6 commit f5342d5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

onadata/apps/logger/migrations/0031_update_schema_after_pyxform_upgrade.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,11 @@ def update_xform_schema(apps, schema_editor):
9292
from onadata.apps.logger.models.xform import XForm as LiveXForm
9393

9494
XForm = apps.get_model("logger", "XForm")
95-
xform_qs = XForm.objects.filter(deleted_at__isnull=True, encrypted=False).only(
96-
"id", "json"
97-
)
95+
xform_qs = XForm.objects.filter(deleted_at__isnull=True, encrypted=False).only("id")
9896
processed = 0
9997
patched = 0
10098

101-
for xform in xform_qs.iterator(chunk_size=50):
99+
for xform in xform_qs.iterator(chunk_size=100):
102100
processed += 1
103101
print(f"processed {processed} xforms")
104102

@@ -114,9 +112,11 @@ def update_xform_schema(apps, schema_editor):
114112
survey = LiveXForm.objects.get(id=xform.id).get_survey_from_xlsform()
115113
XForm.objects.filter(id=xform.id).update(json=survey.to_json_dict())
116114

117-
except (KeyError, PyXFormError):
115+
except (KeyError, PyXFormError, TypeError):
118116
# If the full schema creation fails, try to patch the JSON
119-
print(f"recreating XForm {xform.id} failed, perfoming patch")
117+
print(
118+
f"regenerating schema for XForm {xform.id} failed, performing patch"
119+
)
120120
process_children(json_data["children"], ensure_choices_exist(json_data))
121121
XForm.objects.filter(id=xform.id).update(json=json_data)
122122
patched += 1

0 commit comments

Comments
 (0)