Skip to content

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

Add index for orders user_email and user_id (#14822)

Krzysztof Kwaśniakd042d37fc196
diff --git a/saleor/order/migrations/0171_order_order_user_email_user_id_idx.py b/saleor/order/migrations/0171_order_order_user_email_user_id_idx.py
new file mode 100644
index 0000000000..3d09f79689
--- /dev/null
+++ b/saleor/order/migrations/0171_order_order_user_email_user_id_idx.py
@@ -0,0 +1,22 @@
+# Generated by Django 3.2.22 on 2023-11-22 08:58
+
+import django.contrib.postgres.indexes
+from django.contrib.postgres.operations import AddIndexConcurrently
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ atomic = False
+
+ dependencies = [
+ ("order", "0170_merge_20231030_0857"),
+ ]
+
+ operations = [
+ AddIndexConcurrently(
+ model_name="order",
+ index=django.contrib.postgres.indexes.GinIndex(
+ fields=["user_email", "user_id"], name="order_user_email_user_id_idx"
+ ),
+ ),
+ ]
diff --git a/saleor/order/migrations/0175_merge_20231122_1040.py b/saleor/order/migrations/0175_merge_20231122_1040.py
new file mode 100644
index 0000000000..fd777dba9d
--- /dev/null
+++ b/saleor/order/migrations/0175_merge_20231122_1040.py
@@ -0,0 +1,12 @@
+# Generated by Django 3.2.23 on 2023-11-22 10:40
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("order", "0171_order_order_user_email_user_id_idx"),
+ ("order", "0174_merge_20231030_1033"),
+ ]
+
+ operations = []
diff --git a/saleor/order/migrations/0176_merge_20231122_1346.py b/saleor/order/migrations/0176_merge_20231122_1346.py
new file mode 100644
index 0000000000..f5dc5ad6c1
--- /dev/null
+++ b/saleor/order/migrations/0176_merge_20231122_1346.py
@@ -0,0 +1,12 @@
+# Generated by Django 3.2.22 on 2023-11-22 13:46
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("order", "0175_merge_20231030_1040"),
+ ("order", "0175_merge_20231122_1040"),
+ ]
+
+ operations = []
diff --git a/saleor/order/migrations/0179_merge_20231122_1348.py b/saleor/order/migrations/0179_merge_20231122_1348.py
new file mode 100644
index 0000000000..3179b0ef12
--- /dev/null
+++ b/saleor/order/migrations/0179_merge_20231122_1348.py
@@ -0,0 +1,12 @@
+# Generated by Django 3.2.22 on 2023-11-22 13:48
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("order", "0176_merge_20231122_1346"),
+ ("order", "0178_merge_20231030_1055"),
+ ]
+
+ operations = []
diff --git a/saleor/order/models.py b/saleor/order/models.py
index d8e2e6ed5c..7dfbfd882f 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -353,6 +353,10 @@ class Order(ModelWithMetadata, ModelWithExternalReference):
),
models.Index(fields=["created_at"], name="idx_order_created_at"),
GinIndex(fields=["voucher_code"], name="order_voucher_code_idx"),
+ GinIndex(
+ fields=["user_email", "user_id"],
+ name="order_user_email_user_id_idx",
+ ),
]
def is_fully_paid(self):