db optimize

This commit is contained in:
2026-04-07 16:59:50 +03:30
parent 87d0ea3792
commit 61ecfcf329
8 changed files with 7 additions and 12 deletions
@@ -5,7 +5,6 @@ import { Food } from '../../foods/entities/food.entity';
@Entity({ tableName: 'order_items' })
@Index({ properties: ['order'] })
@Index({ properties: ['food'] })
export class OrderItem extends BaseEntity {
@ManyToOne(() => Order)
order!: Order;
+1 -3
View File
@@ -22,11 +22,9 @@ import { OrderUserAddress, OrderCarAddress } from '../interface/order.interface'
import { Payment } from 'src/modules/payments/entities/payment.entity';
@Entity({ tableName: 'orders' })
@Unique({ properties: ['restaurant', 'orderNumber'] })
@Index({ properties: ['restaurant'] })
@Index({ properties: ['restaurant', 'status'] })
@Index({ properties: ['user', 'status'] })
@Index({ properties: ['restaurant', 'orderNumber'] })
@Index({ properties: ['status'] })
export class Order extends BaseEntity {
@ManyToOne(() => User)
user!: User;
@@ -4,8 +4,8 @@ import { Delivery } from '../../delivery/entities/delivery.entity';
import { PlanEnum } from '../interface/plan.interface';
@Entity({ tableName: 'restaurants' })
@Index({ properties: ['isActive'] })
@Index({ properties: ['slug', 'isActive'] })
@Index({ properties: ['slug'] })
export class Restaurant extends BaseEntity {
// --- اطلاعات پایه ---
@Property()
@@ -1,7 +1,8 @@
import { Entity, Property } from '@mikro-orm/core';
import { Entity, Index, Property } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
@Entity({ tableName: 'schedules' })
@Index({ properties: ['restId'] })
export class Schedule extends BaseEntity {
@Property({ type: 'int' })
weekDay!: number;
@@ -7,8 +7,6 @@ import { PointTransactionType } from '../interface/point';
@Entity({ tableName: 'point_transactions' })
@Index({ properties: ['user', 'restaurant'] }) // Composite index for most common query: find wallet by user and restaurant
@Index({ properties: ['user'] }) // Index for queries finding all wallets for a user
@Index({ properties: ['restaurant'] }) // Index for queries finding all wallets for a restaurant
export class PointTransaction extends BaseEntity {
@ManyToOne(() => User)
user!: User;
@@ -1,8 +1,9 @@
import { Entity, Property, ManyToOne } from '@mikro-orm/core';
import { Entity, Property, ManyToOne, Index } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from './user.entity';
@Entity({ tableName: 'user_addresses' })
@Index({ properties: ['user'] })
export class UserAddress extends BaseEntity {
@ManyToOne(() => User)
user!: User;
+1 -1
View File
@@ -5,7 +5,7 @@ import { Order } from 'src/modules/orders/entities/order.entity';
import { normalizePhone } from '../../utils/phone.util';
@Entity({ tableName: 'users' })
@Index({ properties: ['isActive'] })
@Index({ properties: ['phone'] })
export class User extends BaseEntity {
@OneToMany(() => Order, order => order.user)
orders = new Collection<Order>(this);
@@ -6,8 +6,6 @@ import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
@Entity({ tableName: 'wallet_transactions' })
@Index({ properties: ['user', 'restaurant'] })
@Index({ properties: ['user'] })
@Index({ properties: ['restaurant'] })
export class WalletTransaction extends BaseEntity {
@ManyToOne(() => User)
user!: User;