-
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.
feat(scopes): denormalize full_name and use it for sorting
The full_name attribute on the Scopes was dynamically generated on access. This is rather inefficient, as it may cause a bunch of DB hits, especially in deep hierarchies. Additionally, most of the time we want scopes to be sorted in a meaningful manner (namely, by hierarchical name). MPTTModel supports this, but as the ordering may differ between languages, we cannot use that functionality. This is a secondary use of the denormalized full_name. This also required a fix in the case insensitive ordering code, as localized fields were not treated correctly yet (casting directly to text instead of extracting the correct language and using that to sort)
- Loading branch information
Showing
8 changed files
with
136 additions
and
48 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,32 @@ | ||
# Generated by Django 3.2.15 on 2022-09-23 09:13 | ||
|
||
from django.db import migrations | ||
import localized_fields.fields.char_field | ||
|
||
from emeis.core import models | ||
|
||
|
||
def set_full_name(apps, schema_editor): | ||
scope_model = apps.get_model("emeis_core.scope") | ||
for scope in scope_model.objects.all().iterator(): | ||
# explicitly trigger the set_full_name signal handler | ||
models.set_full_name(instance=scope, sender=set_full_name) | ||
scope.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("emeis_core", "0009_alter_scope_parent"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="scope", | ||
name="full_name", | ||
field=localized_fields.fields.char_field.LocalizedCharField( | ||
blank=True, null=True, required=[], verbose_name="scope name" | ||
), | ||
), | ||
migrations.RunPython(set_full_name, 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.