Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add ginindex for meta fields

Maciej Korycinski52ba8f843bde
diff --git a/saleor/account/migrations/0048_auto_20210308_1135.py b/saleor/account/migrations/0048_auto_20210308_1135.py
new file mode 100644
index 0000000000..e4df165ee4
--- /dev/null
+++ b/saleor/account/migrations/0048_auto_20210308_1135.py
@@ -0,0 +1,26 @@
+# Generated by Django 3.1.7 on 2021-03-08 11:35
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("account", "0047_auto_20200810_1415"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="user",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="user_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="user",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="user_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/account/models.py b/saleor/account/models.py
index e46fb23480..4af990f911 100644
--- a/saleor/account/models.py
+++ b/saleor/account/models.py
@@ -157,7 +157,7 @@ class User(PermissionsMixin, ModelWithMetadata, AbstractBaseUser):
objects = UserManager()
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("email",)
permissions = (
(AccountPermissions.MANAGE_USERS.codename, "Manage customers."),
diff --git a/saleor/app/migrations/0004_auto_20210308_1135.py b/saleor/app/migrations/0004_auto_20210308_1135.py
new file mode 100644
index 0000000000..a164717508
--- /dev/null
+++ b/saleor/app/migrations/0004_auto_20210308_1135.py
@@ -0,0 +1,26 @@
+# Generated by Django 3.1.7 on 2021-03-08 11:35
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("app", "0003_auto_20200810_1415"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="app",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="app_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="app",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="app_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/app/models.py b/saleor/app/models.py
index 27f370309a..865eb13750 100644
--- a/saleor/app/models.py
+++ b/saleor/app/models.py
@@ -33,7 +33,7 @@ class App(ModelWithMetadata):
app_url = models.URLField(blank=True, null=True)
version = models.CharField(max_length=60, blank=True, null=True)
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("name", "pk")
permissions = (
(
diff --git a/saleor/attribute/migrations/0007_auto_20210308_1135.py b/saleor/attribute/migrations/0007_auto_20210308_1135.py
new file mode 100644
index 0000000000..03a281617a
--- /dev/null
+++ b/saleor/attribute/migrations/0007_auto_20210308_1135.py
@@ -0,0 +1,26 @@
+# Generated by Django 3.1.7 on 2021-03-08 11:35
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("attribute", "0006_auto_20210105_1031"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="attribute",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="attribute_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="attribute",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="attribute_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/attribute/models/base.py b/saleor/attribute/models/base.py
index 4dba18c130..92c6792469 100644
--- a/saleor/attribute/models/base.py
+++ b/saleor/attribute/models/base.py
@@ -147,7 +147,7 @@ class Attribute(ModelWithMetadata):
objects = AttributeQuerySet.as_manager()
translated = TranslationProxy()
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("storefront_search_position", "slug")
def __str__(self) -> str:
diff --git a/saleor/checkout/migrations/0032_auto_20210308_1135.py b/saleor/checkout/migrations/0032_auto_20210308_1135.py
new file mode 100644
index 0000000000..ee250fb86c
--- /dev/null
+++ b/saleor/checkout/migrations/0032_auto_20210308_1135.py
@@ -0,0 +1,26 @@
+# Generated by Django 3.1.7 on 2021-03-08 11:35
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("checkout", "0031_auto_20210303_1045"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="checkout",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="checkout_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="checkout",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="checkout_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.py
index b3c36bdbac..80f5315e26 100644
--- a/saleor/checkout/models.py
+++ b/saleor/checkout/models.py
@@ -88,7 +88,7 @@ class Checkout(ModelWithMetadata):
redirect_url = models.URLField(blank=True, null=True)
tracking_code = models.CharField(max_length=255, blank=True, null=True)
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("-last_change", "pk")
permissions = (
(CheckoutPermissions.MANAGE_CHECKOUTS.codename, "Manage checkouts"),
diff --git a/saleor/core/models.py b/saleor/core/models.py
index 2a0f0ed626..3025f54981 100644
--- a/saleor/core/models.py
+++ b/saleor/core/models.py
@@ -1,6 +1,7 @@
import datetime
from typing import Any
+from django.contrib.postgres.indexes import GinIndex
from django.db import models
from django.db.models import JSONField # type: ignore
from django.db.models import F, Max, Q
@@ -79,6 +80,10 @@ class ModelWithMetadata(models.Model):
metadata = JSONField(blank=True, null=True, default=dict, encoder=CustomJsonEncoder)
class Meta:
+ indexes = [
+ GinIndex(fields=["private_metadata"], name="%(class)s_p_meta_idx"),
+ GinIndex(fields=["metadata"], name="%(class)s_meta_idx"),
+ ]
abstract = True
def get_value_from_private_metadata(self, key: str, default: Any = None) -> Any:
diff --git a/saleor/invoice/migrations/0005_auto_20210308_1135.py b/saleor/invoice/migrations/0005_auto_20210308_1135.py
new file mode 100644
index 0000000000..9eeb31d0ae
--- /dev/null
+++ b/saleor/invoice/migrations/0005_auto_20210308_1135.py
@@ -0,0 +1,26 @@
+# Generated by Django 3.1.7 on 2021-03-08 11:35
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("invoice", "0004_auto_20200810_1415"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="invoice",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="invoice_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="invoice",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="invoice_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/menu/migrations/0021_auto_20210308_1135.py b/saleor/menu/migrations/0021_auto_20210308_1135.py
new file mode 100644
index 0000000000..e933cb58fa
--- /dev/null
+++ b/saleor/menu/migrations/0021_auto_20210308_1135.py
@@ -0,0 +1,38 @@
+# Generated by Django 3.1.7 on 2021-03-08 11:35
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("menu", "0020_auto_20201223_0845"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="menu",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="menu_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="menu",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="menu_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="menuitem",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="menuitem_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="menuitem",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="menuitem_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/menu/models.py b/saleor/menu/models.py
index 5011f809fa..fd1e90c6a9 100644
--- a/saleor/menu/models.py
+++ b/saleor/menu/models.py
@@ -13,7 +13,7 @@ class Menu(ModelWithMetadata):
name = models.CharField(max_length=250)
slug = models.SlugField(max_length=255, unique=True, allow_unicode=True)
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("pk",)
permissions = ((MenuPermissions.MANAGE_MENUS.codename, "Manage navigation."),)
@@ -42,7 +42,7 @@ class MenuItem(ModelWithMetadata, MPTTModel, SortableModel):
tree = TreeManager()
translated = TranslationProxy()
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("sort_order", "pk")
app_label = "menu"
diff --git a/saleor/order/migrations/0101_auto_20210308_1213.py b/saleor/order/migrations/0101_auto_20210308_1213.py
new file mode 100644
index 0000000000..f7b061b100
--- /dev/null
+++ b/saleor/order/migrations/0101_auto_20210308_1213.py
@@ -0,0 +1,38 @@
+# Generated by Django 3.1.7 on 2021-03-08 12:13
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("order", "0100_auto_20210216_0914"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="fulfillment",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="fulfillment_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="fulfillment",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="fulfillment_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="order",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="order_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="order",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="order_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 9ad3767289..6aec0ef2c4 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -208,7 +208,7 @@ class Order(ModelWithMetadata):
redirect_url = models.URLField(blank=True, null=True)
objects = OrderQueryset.as_manager()
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("-pk",)
permissions = ((OrderPermissions.MANAGE_ORDERS.codename, "Manage orders."),)
@@ -522,7 +522,7 @@ class Fulfillment(ModelWithMetadata):
tracking_number = models.CharField(max_length=255, default="", blank=True)
created = models.DateTimeField(auto_now_add=True)
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("pk",)
def __str__(self):
diff --git a/saleor/page/migrations/0021_auto_20210308_1135.py b/saleor/page/migrations/0021_auto_20210308_1135.py
new file mode 100644
index 0000000000..1402a751ce
--- /dev/null
+++ b/saleor/page/migrations/0021_auto_20210308_1135.py
@@ -0,0 +1,38 @@
+# Generated by Django 3.1.7 on 2021-03-08 11:35
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("page", "0020_update_content_fields"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="page",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="page_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="page",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="page_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="pagetype",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="pagetype_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="pagetype",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="pagetype_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/page/models.py b/saleor/page/models.py
index 20126fa92a..7802a4fd6a 100644
--- a/saleor/page/models.py
+++ b/saleor/page/models.py
@@ -19,7 +19,7 @@ class Page(ModelWithMetadata, SeoModel, PublishableModel):
translated = TranslationProxy()
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("slug",)
permissions = ((PagePermissions.MANAGE_PAGES.codename, "Manage pages."),)
@@ -56,7 +56,7 @@ class PageType(ModelWithMetadata):
name = models.CharField(max_length=250)
slug = models.SlugField(max_length=255, unique=True, allow_unicode=True)
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("slug",)
permissions = (
(
diff --git a/saleor/product/migrations/0142_auto_20210308_1135.py b/saleor/product/migrations/0142_auto_20210308_1135.py
new file mode 100644
index 0000000000..c92e1a02c4
--- /dev/null
+++ b/saleor/product/migrations/0142_auto_20210308_1135.py
@@ -0,0 +1,86 @@
+# Generated by Django 3.1.7 on 2021-03-08 11:35
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("product", "0141_update_descritpion_fields"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="category",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="category_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="category",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="category_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="collection",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="collection_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="collection",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="collection_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="digitalcontent",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="digitalcontent_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="digitalcontent",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="digitalcontent_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="product",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="product_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="product",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="product_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="producttype",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="producttype_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="producttype",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="producttype_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="productvariant",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="productvariant_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="productvariant",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="productvariant_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 2d632e4f11..e4ef7cf8ea 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -56,7 +56,7 @@ if TYPE_CHECKING:
from ..app.models import App
-class Category(MPTTModel, ModelWithMetadata, SeoModel):
+class Category(ModelWithMetadata, MPTTModel, SeoModel):
name = models.CharField(max_length=250)
slug = models.SlugField(max_length=255, unique=True, allow_unicode=True)
description = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
@@ -110,7 +110,7 @@ class ProductType(ModelWithMetadata):
measurement=Weight, unit_choices=WeightUnits.CHOICES, default=zero_weight
)
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("slug",)
app_label = "product"
permissions = (
@@ -339,6 +339,7 @@ class Product(SeoModel, ModelWithMetadata):
(ProductPermissions.MANAGE_PRODUCTS.codename, "Manage products."),
)
indexes = [GinIndex(fields=["search_vector"])]
+ indexes.extend(ModelWithMetadata.Meta.indexes)
def __iter__(self):
if not hasattr(self, "__variants"):
@@ -459,7 +460,7 @@ class ProductVariant(SortableModel, ModelWithMetadata):
objects = ProductVariantQueryset.as_manager()
translated = TranslationProxy()
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("sort_order", "sku")
app_label = "product"
@@ -698,7 +699,7 @@ class Collection(SeoModel, ModelWithMetadata):
translated = TranslationProxy()
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("slug",)
def __str__(self) -> str:
diff --git a/saleor/shipping/migrations/0028_auto_20210308_1135.py b/saleor/shipping/migrations/0028_auto_20210308_1135.py
new file mode 100644
index 0000000000..ee1b05f04d
--- /dev/null
+++ b/saleor/shipping/migrations/0028_auto_20210308_1135.py
@@ -0,0 +1,38 @@
+# Generated by Django 3.1.7 on 2021-03-08 11:35
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("shipping", "0027_auto_20210120_2201"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="shippingmethod",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="shippingmethod_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="shippingmethod",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="shippingmethod_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="shippingzone",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="shippingzone_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="shippingzone",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="shippingzone_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/shipping/models.py b/saleor/shipping/models.py
index 9e59918613..efbc3740f3 100644
--- a/saleor/shipping/models.py
+++ b/saleor/shipping/models.py
@@ -81,7 +81,7 @@ class ShippingZone(ModelWithMetadata):
def __str__(self):
return self.name
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
permissions = (
(ShippingPermissions.MANAGE_SHIPPING.codename, "Manage shipping."),
)
@@ -194,7 +194,7 @@ class ShippingMethod(ModelWithMetadata):
objects = ShippingMethodQueryset.as_manager()
translated = TranslationProxy()
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("pk",)
def __str__(self):
diff --git a/saleor/warehouse/migrations/0013_auto_20210308_1135.py b/saleor/warehouse/migrations/0013_auto_20210308_1135.py
new file mode 100644
index 0000000000..0ed580b941
--- /dev/null
+++ b/saleor/warehouse/migrations/0013_auto_20210308_1135.py
@@ -0,0 +1,26 @@
+# Generated by Django 3.1.7 on 2021-03-08 11:35
+
+import django.contrib.postgres.indexes
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("warehouse", "0012_auto_20210115_1307"),
+ ]
+
+ operations = [
+ migrations.AddIndex(
+ model_name="warehouse",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["private_metadata"], name="warehouse_p_meta_idx"
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="warehouse",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["metadata"], name="warehouse_meta_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/warehouse/models.py b/saleor/warehouse/models.py
index d151b406e7..c039bfed53 100644
--- a/saleor/warehouse/models.py
+++ b/saleor/warehouse/models.py
@@ -38,7 +38,7 @@ class Warehouse(ModelWithMetadata):
objects = WarehouseQueryset.as_manager()
- class Meta:
+ class Meta(ModelWithMetadata.Meta):
ordering = ("-slug",)
def __str__(self):