feat(guild-model): add practical indexes for channel/dm/member queries
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
@Entity('channels')
|
@Entity('channels')
|
||||||
|
@Index(['guildId', 'createdAt'])
|
||||||
export class Channel {
|
export class Channel {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
|
@Index()
|
||||||
@Column({ type: 'char', length: 36 })
|
@Column({ type: 'char', length: 36 })
|
||||||
guildId!: string;
|
guildId!: string;
|
||||||
|
|
||||||
@@ -22,5 +24,6 @@ export class Channel {
|
|||||||
lastSeq!: number;
|
lastSeq!: number;
|
||||||
|
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
|
@Index()
|
||||||
createdAt!: Date;
|
createdAt!: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
@Entity('dm_conversations')
|
@Entity('dm_conversations')
|
||||||
export class DmConversation {
|
export class DmConversation {
|
||||||
@@ -12,5 +12,6 @@ export class DmConversation {
|
|||||||
topic!: string | null;
|
topic!: string | null;
|
||||||
|
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
|
@Index()
|
||||||
createdAt!: Date;
|
createdAt!: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
@Entity('dm_participants')
|
@Entity('dm_participants')
|
||||||
|
@Index(['conversationId', 'userId'], { unique: true })
|
||||||
export class DmParticipant {
|
export class DmParticipant {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
|
@Index()
|
||||||
@Column({ type: 'char', length: 36 })
|
@Column({ type: 'char', length: 36 })
|
||||||
conversationId!: string;
|
conversationId!: string;
|
||||||
|
|
||||||
|
@Index()
|
||||||
@Column({ type: 'varchar', length: 64 })
|
@Column({ type: 'varchar', length: 64 })
|
||||||
userId!: string;
|
userId!: string;
|
||||||
|
|
||||||
@@ -15,5 +18,6 @@ export class DmParticipant {
|
|||||||
role!: 'member';
|
role!: 'member';
|
||||||
|
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
|
@Index()
|
||||||
createdAt!: Date;
|
createdAt!: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
@Entity('guild_members')
|
@Entity('guild_members')
|
||||||
|
@Index(['guildId', 'userId'], { unique: true })
|
||||||
|
@Index(['guildId', 'status'])
|
||||||
export class GuildMember {
|
export class GuildMember {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
|
@Index()
|
||||||
@Column({ type: 'char', length: 36 })
|
@Column({ type: 'char', length: 36 })
|
||||||
guildId!: string;
|
guildId!: string;
|
||||||
|
|
||||||
|
@Index()
|
||||||
@Column({ type: 'varchar', length: 64 })
|
@Column({ type: 'varchar', length: 64 })
|
||||||
userId!: string;
|
userId!: string;
|
||||||
|
|
||||||
@@ -15,5 +19,6 @@ export class GuildMember {
|
|||||||
status!: 'active' | 'left' | 'blocked';
|
status!: 'active' | 'left' | 'blocked';
|
||||||
|
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
|
@Index()
|
||||||
createdAt!: Date;
|
createdAt!: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from
|
|||||||
@Entity('messages')
|
@Entity('messages')
|
||||||
@Index(['channelId', 'seq'], { unique: true })
|
@Index(['channelId', 'seq'], { unique: true })
|
||||||
@Index(['conversationId', 'seq'], { unique: true })
|
@Index(['conversationId', 'seq'], { unique: true })
|
||||||
|
@Index(['channelId', 'createdAt'])
|
||||||
|
@Index(['conversationId', 'createdAt'])
|
||||||
export class Message {
|
export class Message {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id!: string;
|
id!: string;
|
||||||
@@ -25,5 +27,6 @@ export class Message {
|
|||||||
content!: string;
|
content!: string;
|
||||||
|
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
|
@Index()
|
||||||
createdAt!: Date;
|
createdAt!: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
### 2.1 领域模型
|
### 2.1 领域模型
|
||||||
- [x] Guild/Channel/DM 实体补全
|
- [x] Guild/Channel/DM 实体补全
|
||||||
- [x] Member/Role 基础模型(即使 MVP 权限全开,也先留结构)
|
- [x] Member/Role 基础模型(即使 MVP 权限全开,也先留结构)
|
||||||
- [ ] 索引设计(channel_id + seq, created_at 等)
|
- [x] 索引设计(channel_id + seq, created_at 等)
|
||||||
|
|
||||||
### 2.2 消息主链路
|
### 2.2 消息主链路
|
||||||
- [ ] 发送消息(content/reply/mentions/attachments 元数据)
|
- [ ] 发送消息(content/reply/mentions/attachments 元数据)
|
||||||
|
|||||||
Reference in New Issue
Block a user