Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES/7477.bugfix
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 18 additions & 0 deletions pulpcore/app/migrations/0146_content_pulp_labels_gin.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
4 changes: 4 additions & 0 deletions pulpcore/app/models/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
]
Expand Down
4 changes: 2 additions & 2 deletions pulpcore/app/viewsets/custom_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Loading