db optimize
This commit is contained in:
@@ -5,7 +5,6 @@ import { Food } from '../../foods/entities/food.entity';
|
|||||||
|
|
||||||
@Entity({ tableName: 'order_items' })
|
@Entity({ tableName: 'order_items' })
|
||||||
@Index({ properties: ['order'] })
|
@Index({ properties: ['order'] })
|
||||||
@Index({ properties: ['food'] })
|
|
||||||
export class OrderItem extends BaseEntity {
|
export class OrderItem extends BaseEntity {
|
||||||
@ManyToOne(() => Order)
|
@ManyToOne(() => Order)
|
||||||
order!: Order;
|
order!: Order;
|
||||||
|
|||||||
@@ -22,11 +22,9 @@ import { OrderUserAddress, OrderCarAddress } from '../interface/order.interface'
|
|||||||
import { Payment } from 'src/modules/payments/entities/payment.entity';
|
import { Payment } from 'src/modules/payments/entities/payment.entity';
|
||||||
|
|
||||||
@Entity({ tableName: 'orders' })
|
@Entity({ tableName: 'orders' })
|
||||||
@Unique({ properties: ['restaurant', 'orderNumber'] })
|
@Index({ properties: ['restaurant'] })
|
||||||
@Index({ properties: ['restaurant', 'status'] })
|
@Index({ properties: ['restaurant', 'status'] })
|
||||||
@Index({ properties: ['user', 'status'] })
|
|
||||||
@Index({ properties: ['restaurant', 'orderNumber'] })
|
@Index({ properties: ['restaurant', 'orderNumber'] })
|
||||||
@Index({ properties: ['status'] })
|
|
||||||
export class Order extends BaseEntity {
|
export class Order extends BaseEntity {
|
||||||
@ManyToOne(() => User)
|
@ManyToOne(() => User)
|
||||||
user!: User;
|
user!: User;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { Delivery } from '../../delivery/entities/delivery.entity';
|
|||||||
import { PlanEnum } from '../interface/plan.interface';
|
import { PlanEnum } from '../interface/plan.interface';
|
||||||
|
|
||||||
@Entity({ tableName: 'restaurants' })
|
@Entity({ tableName: 'restaurants' })
|
||||||
@Index({ properties: ['isActive'] })
|
|
||||||
@Index({ properties: ['slug', 'isActive'] })
|
@Index({ properties: ['slug', 'isActive'] })
|
||||||
|
@Index({ properties: ['slug'] })
|
||||||
export class Restaurant extends BaseEntity {
|
export class Restaurant extends BaseEntity {
|
||||||
// --- اطلاعات پایه ---
|
// --- اطلاعات پایه ---
|
||||||
@Property()
|
@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';
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||||
|
|
||||||
@Entity({ tableName: 'schedules' })
|
@Entity({ tableName: 'schedules' })
|
||||||
|
@Index({ properties: ['restId'] })
|
||||||
export class Schedule extends BaseEntity {
|
export class Schedule extends BaseEntity {
|
||||||
@Property({ type: 'int' })
|
@Property({ type: 'int' })
|
||||||
weekDay!: number;
|
weekDay!: number;
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import { PointTransactionType } from '../interface/point';
|
|||||||
|
|
||||||
@Entity({ tableName: 'point_transactions' })
|
@Entity({ tableName: 'point_transactions' })
|
||||||
@Index({ properties: ['user', 'restaurant'] }) // Composite index for most common query: find wallet by user and restaurant
|
@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 {
|
export class PointTransaction extends BaseEntity {
|
||||||
@ManyToOne(() => User)
|
@ManyToOne(() => User)
|
||||||
user!: 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 { BaseEntity } from '../../../common/entities/base.entity';
|
||||||
import { User } from './user.entity';
|
import { User } from './user.entity';
|
||||||
|
|
||||||
@Entity({ tableName: 'user_addresses' })
|
@Entity({ tableName: 'user_addresses' })
|
||||||
|
@Index({ properties: ['user'] })
|
||||||
export class UserAddress extends BaseEntity {
|
export class UserAddress extends BaseEntity {
|
||||||
@ManyToOne(() => User)
|
@ManyToOne(() => User)
|
||||||
user!: User;
|
user!: User;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Order } from 'src/modules/orders/entities/order.entity';
|
|||||||
import { normalizePhone } from '../../utils/phone.util';
|
import { normalizePhone } from '../../utils/phone.util';
|
||||||
|
|
||||||
@Entity({ tableName: 'users' })
|
@Entity({ tableName: 'users' })
|
||||||
@Index({ properties: ['isActive'] })
|
@Index({ properties: ['phone'] })
|
||||||
export class User extends BaseEntity {
|
export class User extends BaseEntity {
|
||||||
@OneToMany(() => Order, order => order.user)
|
@OneToMany(() => Order, order => order.user)
|
||||||
orders = new Collection<Order>(this);
|
orders = new Collection<Order>(this);
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
|
|||||||
|
|
||||||
@Entity({ tableName: 'wallet_transactions' })
|
@Entity({ tableName: 'wallet_transactions' })
|
||||||
@Index({ properties: ['user', 'restaurant'] })
|
@Index({ properties: ['user', 'restaurant'] })
|
||||||
@Index({ properties: ['user'] })
|
|
||||||
@Index({ properties: ['restaurant'] })
|
|
||||||
export class WalletTransaction extends BaseEntity {
|
export class WalletTransaction extends BaseEntity {
|
||||||
@ManyToOne(() => User)
|
@ManyToOne(() => User)
|
||||||
user!: User;
|
user!: User;
|
||||||
|
|||||||
Reference in New Issue
Block a user