Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix performance issue
dex242976e34965
diff --git a/saleor/attribute/migrations/0016_auto_20210827_0938.py b/saleor/attribute/migrations/0016_auto_20210827_0938.pynew file mode 100644index 0000000000..e821c5a96c--- /dev/null+++ b/saleor/attribute/migrations/0016_auto_20210827_0938.py@@ -0,0 +1,26 @@+# Generated by Django 3.2.6 on 2021-08-27 09:38++import django.contrib.postgres.indexes+from django.db import migrations+++class Migration(migrations.Migration):++ dependencies = [+ ("attribute", "0015_auto_20210817_1015"),+ ]++ operations = [+ migrations.RemoveIndex(+ model_name="attributevalue",+ name="attribute_a_name_9f3448_gin",+ ),+ migrations.AddIndex(+ model_name="attributevalue",+ index=django.contrib.postgres.indexes.GinIndex(+ fields=["name", "slug"],+ name="attribute_search_gin",+ opclasses=["gin_trgm_ops", "gin_trgm_ops"],+ ),+ ),+ ]diff --git a/saleor/attribute/models/base.py b/saleor/attribute/models/base.pyindex 0e8847829f..3584295ee8 100644--- a/saleor/attribute/models/base.py+++ b/saleor/attribute/models/base.py@@ -213,7 +213,14 @@ class AttributeValue(SortableModel):class Meta:ordering = ("sort_order", "pk")unique_together = ("slug", "attribute")- indexes = [GinIndex(fields=["name", "slug"])]+ indexes = [+ GinIndex(+ name="attribute_search_gin",+ # `opclasses` and `fields` should be the same length+ fields=["name", "slug"],+ opclasses=["gin_trgm_ops"] * 2,+ )+ ]def __str__(self) -> str:return self.namediff --git a/saleor/graphql/attribute/filters.py b/saleor/graphql/attribute/filters.pyindex ee563337cd..8e733a29d8 100644--- a/saleor/graphql/attribute/filters.py+++ b/saleor/graphql/attribute/filters.py@@ -65,7 +65,7 @@ class AttributeValueFilter(django_filters.FilterSet):def filter_search(cls, queryset, _name, value):if not value:return queryset- name_slug_qs = Q(name__trigram_similar=value) | Q(slug__trigram_similar=value)+ name_slug_qs = Q(name__ilike=value) | Q(slug__ilike=value)return queryset.filter(name_slug_qs)