From 130e9c47b8f7a4b7a248714dffa896081a431631 Mon Sep 17 00:00:00 2001 From: git-hyagi <45576767+git-hyagi@users.noreply.github.com> Date: Tue, 17 Mar 2026 15:34:45 -0300 Subject: [PATCH] Add a GIN index to the pulp_labels field fix: #7477 Assisted By: claude-opus-4.6 --- CHANGES/7477.bugfix | 2 ++ .../migrations/0146_content_pulp_labels_gin.py | 18 ++++++++++++++++++ pulpcore/app/models/content.py | 4 ++++ pulpcore/app/viewsets/custom_filters.py | 4 ++-- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 CHANGES/7477.bugfix create mode 100644 pulpcore/app/migrations/0146_content_pulp_labels_gin.py diff --git a/CHANGES/7477.bugfix b/CHANGES/7477.bugfix new file mode 100644 index 00000000000..4bdf0e657c8 --- /dev/null +++ b/CHANGES/7477.bugfix @@ -0,0 +1,2 @@ +Added a GIN index to the pulp_labels field on Content and updated label filtering to use +GIN-optimized lookups, improving query performance for label-based content searches. diff --git a/pulpcore/app/migrations/0146_content_pulp_labels_gin.py b/pulpcore/app/migrations/0146_content_pulp_labels_gin.py new file mode 100644 index 00000000000..cb5bd14d853 --- /dev/null +++ b/pulpcore/app/migrations/0146_content_pulp_labels_gin.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.7 on 2026-03-17 18:32 + +import django.contrib.postgres.indexes +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0145_domainize_import_export'), + ] + + operations = [ + migrations.AddIndex( + model_name='content', + index=django.contrib.postgres.indexes.GinIndex(fields=['pulp_labels'], name='pulp_labels_gin_index'), + ), + ] diff --git a/pulpcore/app/models/content.py b/pulpcore/app/models/content.py index 4a6cf2bc36c..041bc94dc90 100644 --- a/pulpcore/app/models/content.py +++ b/pulpcore/app/models/content.py @@ -18,6 +18,7 @@ from django.conf import settings from django.contrib.postgres.fields import HStoreField +from django.contrib.postgres.indexes import GinIndex from django.core import validators from django.db import IntegrityError, models, transaction from django.forms.models import model_to_dict @@ -552,6 +553,9 @@ class Content(MasterModel, QueryMixin): class Meta: verbose_name_plural = "content" unique_together = () + indexes = [ + GinIndex(fields=["pulp_labels"], name="pulp_labels_gin_index"), + ] permissions = [ ("manage_content_labels", "Can manage content-labels"), ] diff --git a/pulpcore/app/viewsets/custom_filters.py b/pulpcore/app/viewsets/custom_filters.py index 16b7e9f504b..4015ebe55c3 100644 --- a/pulpcore/app/viewsets/custom_filters.py +++ b/pulpcore/app/viewsets/custom_filters.py @@ -323,10 +323,10 @@ def filter(self, qs, value): raise DRFValidationError(_("Cannot use an operator with '{}'.").format(key)) if op == "=": - qs = qs.filter(**{f"{field_name}__{key}": val}) + qs = qs.filter(**{f"{field_name}__contains": {key: val}}) elif op == "!=": qs = qs.filter(**{f"{field_name}__has_key": key}).exclude( - **{f"{field_name}__{key}": val} + **{f"{field_name}__contains": {key: val}} ) elif op == "~": qs = qs.filter(**{f"{field_name}__{key}__icontains": val})