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
@@ -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;