-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5105 from kobotoolbox/fix-bad-performance-with-fo…
…rmdisclaimer Fix bad performance introduced in `2.024.25`
- Loading branch information
Showing
4 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
kobo/apps/openrosa/apps/logger/migrations/0035_add_index_on_logger_xform__kpi_asset_uid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Generated by Django 4.2.15 on 2024-09-11 19:33 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
def manually_create_indexes_instructions(apps, schema_editor): | ||
print( | ||
""" | ||
!!! ATTENTION !!! | ||
If you have existing projects you need to run the SQL queries below in PostgreSQL directly: | ||
> CREATE INDEX CONCURRENTLY "logger_xform_kpi_asset_uid_e5e6b08d" ON "logger_xform" ("kpi_asset_uid"); | ||
> CREATE INDEX CONCURRENTLY "logger_xform_kpi_asset_uid_e5e6b08d_like" ON "logger_xform" ("kpi_asset_uid" varchar_pattern_ops); | ||
Otherwise, project views will perform very poorly. | ||
""" | ||
) | ||
|
||
|
||
def manually_drop_indexes_instructions(apps, schema_editor): | ||
print( | ||
""" | ||
!!! ATTENTION !!! | ||
Run the SQL queries below in PostgreSQL directly: | ||
> DROP INDEX IF EXISTS "logger_xform_kpi_asset_uid_e5e6b08d_like"; | ||
> DROP INDEX IF EXISTS "logger_xform_kpi_asset_uid_e5e6b08d"; | ||
""" | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('logger', '0034_set_require_auth_at_project_level'), | ||
] | ||
|
||
if settings.SKIP_HEAVY_MIGRATIONS: | ||
operations = [ | ||
migrations.RunPython( | ||
manually_create_indexes_instructions, | ||
manually_drop_indexes_instructions, | ||
) | ||
] | ||
else: | ||
operations = [ | ||
migrations.AlterField( | ||
model_name='xform', | ||
name='kpi_asset_uid', | ||
field=models.CharField(db_index=True, max_length=32, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
kpi/migrations/0057_add_index_on_kpi_asset__deployment_data__formid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated by Django 4.2.15 on 2024-09-11 19:21 | ||
|
||
import django.contrib.postgres.indexes | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
def manually_create_indexes_instructions(apps, schema_editor): | ||
print( | ||
""" | ||
!!! ATTENTION !!! | ||
If you have existing projects you need to run the SQL queries below in PostgreSQL directly: | ||
> CREATE INDEX CONCURRENTLY "deployment_data__formid_idx" ON kpi_asset USING btree ((("_deployment_data" -> 'formid'))); | ||
Otherwise, project views will perform very poorly. | ||
""" | ||
) | ||
|
||
|
||
def manually_drop_indexes_instructions(apps, schema_editor): | ||
print( | ||
""" | ||
!!! ATTENTION !!! | ||
Run the SQL queries below in PostgreSQL directly: | ||
> DROP INDEX IF EXISTS "deployment_data__formid_idx"; | ||
""" | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('kpi', '0056_fix_add_submission_bad_permission_assignment'), | ||
] | ||
|
||
if settings.SKIP_HEAVY_MIGRATIONS: | ||
operations = [ | ||
migrations.RunPython( | ||
manually_create_indexes_instructions, | ||
manually_drop_indexes_instructions, | ||
) | ||
] | ||
else: | ||
operations = [ | ||
migrations.AddIndex( | ||
model_name='asset', | ||
index=django.contrib.postgres.indexes.BTreeIndex( | ||
models.F('_deployment_data__formid'), | ||
name='deployment_data__formid_idx', | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters