From 996de7aab2eebc9f7148e52f738737c10be29ee0 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Mon, 28 Jul 2025 15:25:37 +0330 Subject: [PATCH] indexes of product --- ...mmentmodel_comment_product_idx_and_more.py | 152 ++++++++++++++++++ backend/product/models.py | 50 +++++- 2 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 backend/product/migrations/0050_commentmodel_comment_product_idx_and_more.py diff --git a/backend/product/migrations/0050_commentmodel_comment_product_idx_and_more.py b/backend/product/migrations/0050_commentmodel_comment_product_idx_and_more.py new file mode 100644 index 0000000..2ffcc3f --- /dev/null +++ b/backend/product/migrations/0050_commentmodel_comment_product_idx_and_more.py @@ -0,0 +1,152 @@ +# Generated by Django 5.1.2 on 2025-07-28 11:44 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0018_remove_showcaseslider_image_and_more'), + ('product', '0049_alter_productmodel_slug'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddIndex( + model_name='commentmodel', + index=models.Index(fields=['product'], name='comment_product_idx'), + ), + migrations.AddIndex( + model_name='commentmodel', + index=models.Index(fields=['review_status'], name='comment_review_status_idx'), + ), + migrations.AddIndex( + model_name='commentmodel', + index=models.Index(fields=['product', 'review_status'], name='comment_product_status_idx'), + ), + migrations.AddIndex( + model_name='commentmodel', + index=models.Index(fields=['user'], name='comment_user_idx'), + ), + migrations.AddIndex( + model_name='commentmodel', + index=models.Index(fields=['timestamp'], name='comment_timestamp_idx'), + ), + migrations.AddIndex( + model_name='detailmodel', + index=models.Index(fields=['detail_model'], name='detail_model_idx'), + ), + migrations.AddIndex( + model_name='detailmodel', + index=models.Index(fields=['title'], name='detail_title_idx'), + ), + migrations.AddIndex( + model_name='dollormodel', + index=models.Index(fields=['unique_filed'], name='dollor_unique_field_idx'), + ), + migrations.AddIndex( + model_name='maincategorymodel', + index=models.Index(fields=['slug'], name='main_category_slug_idx'), + ), + migrations.AddIndex( + model_name='productdetailcategory', + index=models.Index(fields=['title'], name='detail_category_title_idx'), + ), + migrations.AddIndex( + model_name='productdetailmodel', + index=models.Index(fields=['detail_category'], name='product_detail_category_idx'), + ), + migrations.AddIndex( + model_name='productmodel', + index=models.Index(fields=['slug'], name='product_slug_idx'), + ), + migrations.AddIndex( + model_name='productmodel', + index=models.Index(fields=['category'], name='product_category_idx'), + ), + migrations.AddIndex( + model_name='productmodel', + index=models.Index(fields=['name'], name='product_name_idx'), + ), + migrations.AddIndex( + model_name='productmodel', + index=models.Index(fields=['created_at'], name='product_created_at_idx'), + ), + migrations.AddIndex( + model_name='productmodel', + index=models.Index(fields=['show'], name='product_show_idx'), + ), + migrations.AddIndex( + model_name='productmodel', + index=models.Index(fields=['category', 'created_at'], name='product_category_created_idx'), + ), + migrations.AddIndex( + model_name='productmodel', + index=models.Index(fields=['category', 'name'], name='product_category_name_idx'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['product', 'price', 'created_at'], name='idx_product_price_created'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['in_stock', 'discount'], name='idx_stock_discount'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['created_at'], name='idx_created'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['price'], name='idx_price'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['discount'], name='product_variant_discount_idx'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['in_stock'], name='product_variant_in_stock_idx'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['product'], name='product_variant_product_idx'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['slider_category'], name='variant_slider_category_idx'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['slider_category', 'in_stock'], name='variant_slider_stock_idx'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['slider_category', 'discount'], name='variant_slider_discount_idx'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['slider_category', 'created_at'], name='variant_slider_created_idx'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['product', 'in_stock'], name='variant_product_stock_idx'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['product', 'discount'], name='variant_product_discount_idx'), + ), + migrations.AddIndex( + model_name='productvariant', + index=models.Index(fields=['currency'], name='variant_currency_idx'), + ), + migrations.AddIndex( + model_name='subcategorymodel', + index=models.Index(fields=['slug'], name='sub_category_slug_idx'), + ), + migrations.AddIndex( + model_name='subcategorymodel', + index=models.Index(fields=['parent'], name='sub_category_parent_idx'), + ), + ] diff --git a/backend/product/models.py b/backend/product/models.py index 1bbe6bd..02dfa2a 100644 --- a/backend/product/models.py +++ b/backend/product/models.py @@ -17,6 +17,9 @@ class MainCategoryModel(models.Model): class Meta: verbose_name = "دسته‌بندی اصلی" verbose_name_plural = "دسته‌بندی‌هااصلی" + indexes = [ + models.Index(fields=['slug'], name='main_category_slug_idx'), + ] def __str__(self): return self.name @@ -39,6 +42,10 @@ class SubCategoryModel(models.Model): class Meta: verbose_name = "زیر دسته‌بندی" verbose_name_plural = "زیر دسته‌بندی‌ها" + indexes = [ + models.Index(fields=['slug'], name='sub_category_slug_idx'), + models.Index(fields=['parent'], name='sub_category_parent_idx'), + ] def __str__(self): return self.name @@ -84,6 +91,9 @@ class DollorModel(models.Model): class Meta: verbose_name = 'مدل دلار' verbose_name_plural = 'مدل دلار' + indexes = [ + models.Index(fields=['unique_filed'], name='dollor_unique_field_idx'), + ] class InPackItems(models.Model): @@ -127,6 +137,15 @@ class ProductModel(models.Model): class Meta: verbose_name = 'محصول' verbose_name_plural = 'محصولات' + indexes = [ + models.Index(fields=['slug'], name='product_slug_idx'), + models.Index(fields=['category'], name='product_category_idx'), + models.Index(fields=['name'], name='product_name_idx'), + models.Index(fields=['created_at'], name='product_created_at_idx'), + models.Index(fields=['show'], name='product_show_idx'), + models.Index(fields=['category', 'created_at'], name='product_category_created_idx'), + models.Index(fields=['category', 'name'], name='product_category_name_idx'), + ] @@ -140,7 +159,10 @@ class ProductDetailCategory(models.Model): class Meta: verbose_name = 'دسته بندی جزيات' - verbose_name_plural = 'دسته بندی های جزيیات' + verbose_name_plural = 'دسته بندی های جزيیات' + indexes = [ + models.Index(fields=['title'], name='detail_category_title_idx'), + ] @@ -162,6 +184,13 @@ class CommentModel(models.Model): class Meta: verbose_name = 'نظر' verbose_name_plural = 'نظرات' + indexes = [ + models.Index(fields=['product'], name='comment_product_idx'), + models.Index(fields=['review_status'], name='comment_review_status_idx'), + models.Index(fields=['product', 'review_status'], name='comment_product_status_idx'), + models.Index(fields=['user'], name='comment_user_idx'), + models.Index(fields=['timestamp'], name='comment_timestamp_idx'), + ] def __str__(self): return f"{self.user}-{self.content[:30]}" @@ -205,6 +234,9 @@ class ProductDetailModel(models.Model): class Meta: verbose_name = 'جزیات محصول' verbose_name_plural = 'جزیات محصول ها' + indexes = [ + models.Index(fields=['detail_category'], name='product_detail_category_idx'), + ] def __str__(self): return f'جزيیات محصول {self.detail_category.title} - {self.name}' @@ -222,6 +254,10 @@ class DetailModel(models.Model): class Meta: verbose_name = 'مدل جزیات' verbose_name_plural = 'مدل های جزیات' + indexes = [ + models.Index(fields=['detail_model'], name='detail_model_idx'), + models.Index(fields=['title'], name='detail_title_idx'), + ] class ProductVariant(models.Model): @@ -250,6 +286,18 @@ class ProductVariant(models.Model): class Meta: verbose_name = 'تنوع محصول' verbose_name_plural = 'تنوع‌های محصول' + indexes = [ + # Existing indexes + models.Index(fields=['product', 'price', 'created_at'], name='idx_product_price_created'), + models.Index(fields=['in_stock', 'discount'], name='idx_stock_discount'), + models.Index(fields=['created_at'], name='idx_created'), + models.Index(fields=['price'], name='idx_price'), + models.Index(fields=['discount'], name='product_variant_discount_idx'), + models.Index(fields=['in_stock'], name='product_variant_in_stock_idx'), + models.Index(fields=['product'], name='product_variant_product_idx'), + models.Index(fields=['product', 'in_stock'], name='variant_product_stock_idx'), + models.Index(fields=['product', 'discount'], name='variant_product_discount_idx'), + ] def __str__(self): return f"{self.product.name} - {', '.join(str(attr) for attr in self.product_attributes.all())}"