-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: drop django-tree-queries & implement array-based tree funct…
…ions The Django-Tree-Queries, together with some visibility queries, causes a ton of heavy performance problems. Therefore, we now implement the tree functionality for Scopes by using an array field to "cache" all the parent PKs of every scope. This allows us to write some much more efficient queries that don't rely on CTEs, and enables subqueries where we previously had to explode a QS to perform the same functionality.
- Loading branch information
Showing
10 changed files
with
239 additions
and
538 deletions.
There are no files selected for viewing
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
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,54 @@ | ||
# Generated by Django 3.2.25 on 2024-06-13 07:05 | ||
|
||
import django.contrib.postgres.fields | ||
import django.contrib.postgres.indexes | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
def set_all_parents(apps, schema_editor): | ||
from emeis.core.models import set_full_name_and_parents | ||
|
||
scope_model = apps.get_model("emeis_core.scope") | ||
for scope in scope_model.objects.all().iterator(): | ||
# explicitly trigger the set_full_name signal handler | ||
set_full_name_and_parents(instance=scope, sender=set_all_parents) | ||
scope.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("emeis_core", "0011_mptt_to_tree_queries"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="scope", | ||
options={"ordering": ["name"]}, | ||
), | ||
migrations.AddField( | ||
model_name="scope", | ||
name="all_parents", | ||
field=django.contrib.postgres.fields.ArrayField( | ||
base_field=models.UUIDField(), default=list, size=None | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="scope", | ||
name="parent", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="children", | ||
to="emeis_core.scope", | ||
), | ||
), | ||
migrations.AddIndex( | ||
model_name="scope", | ||
index=django.contrib.postgres.indexes.GinIndex( | ||
fields=["all_parents"], name="emeis_core__all_par_f8231c_gin" | ||
), | ||
), | ||
migrations.RunPython(set_all_parents, migrations.RunPython.noop), | ||
] |
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
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
Oops, something went wrong.