-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplemented labels as HStore field
This solves the imminent performance issues. fixes #3400
- Loading branch information
Showing
14 changed files
with
183 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed label querying performance issues. |
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,2 @@ | ||
Deprecated model ``Label`` and serializer field ``LabelField`` and ``LabelSelectFilter`` for | ||
removal in 3.25. |
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,92 @@ | ||
# Generated by Django 3.2.16 on 2022-11-28 08:30 | ||
|
||
import django.contrib.postgres.fields.hstore | ||
from django.db import migrations | ||
|
||
import os | ||
from django.contrib.postgres.operations import HStoreExtension | ||
from django.db.models.expressions import OuterRef, RawSQL | ||
from django.apps import apps as global_apps | ||
from pulpcore.app.apps import PulpPluginAppConfig | ||
|
||
|
||
def copy_labels_up(apps, schema_editor): | ||
ContentType = apps.get_model("contenttypes", "ContentType") | ||
Label = apps.get_model("core", "Label") | ||
|
||
labeled_ctypes = [ContentType.objects.get(pk=pk) for pk in Label.objects.values_list("content_type", flat=True).distinct()] | ||
labeled_models_ctypes = [(apps.get_model(ctype.app_label, ctype.model), ctype) for ctype in labeled_ctypes] | ||
for model, ctype in labeled_models_ctypes: | ||
label_subq = Label.objects.filter(content_type=ctype, object_id=OuterRef("pulp_id")).annotate(label_data=RawSQL("hstore(array_agg(key), array_agg(value))", [])).values("label_data") | ||
model.objects.update(pulp_labels=label_subq) | ||
Label.objects.filter(content_type=ctype).delete() | ||
|
||
if Label.objects.count() != 0: | ||
raise RuntimeError("Not all labels could be migrated properly. Please raise an issue and stand by for further investigation.") | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0096_alter_task_logging_cid'), | ||
('contenttypes', '0002_remove_content_type_name'), | ||
] | ||
# Depend on all installed plugins containing migrations to be able to use their models. | ||
for plugin_config in global_apps.app_configs.values(): | ||
if isinstance(plugin_config, PulpPluginAppConfig) and os.path.exists(plugin_config.path + "/migrations/0001_initial.py"): | ||
dependencies.append((plugin_config.label, '0001_initial')) | ||
|
||
operations = [ | ||
HStoreExtension(), | ||
migrations.AddField( | ||
model_name='alternatecontentsource', | ||
name='pulp_labels', | ||
field=django.contrib.postgres.fields.hstore.HStoreField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='basedistribution', | ||
name='pulp_labels', | ||
field=django.contrib.postgres.fields.hstore.HStoreField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='content', | ||
name='pulp_labels', | ||
field=django.contrib.postgres.fields.hstore.HStoreField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='contentguard', | ||
name='pulp_labels', | ||
field=django.contrib.postgres.fields.hstore.HStoreField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='distribution', | ||
name='pulp_labels', | ||
field=django.contrib.postgres.fields.hstore.HStoreField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='exporter', | ||
name='pulp_labels', | ||
field=django.contrib.postgres.fields.hstore.HStoreField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='importer', | ||
name='pulp_labels', | ||
field=django.contrib.postgres.fields.hstore.HStoreField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='publication', | ||
name='pulp_labels', | ||
field=django.contrib.postgres.fields.hstore.HStoreField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='remote', | ||
name='pulp_labels', | ||
field=django.contrib.postgres.fields.hstore.HStoreField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='repository', | ||
name='pulp_labels', | ||
field=django.contrib.postgres.fields.hstore.HStoreField(default=dict), | ||
), | ||
migrations.RunPython(code=copy_labels_up, reverse_code=migrations.RunPython.noop, elidable=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
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
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
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
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.