Compare commits

...

1 Commits

Author SHA1 Message Date
YuTengjing 5051111f93 ️perf: optimize index for admin 2025-12-12 16:48:17 +08:00
3 changed files with 11 additions and 0 deletions
+1
View File
@@ -64,6 +64,7 @@ export const agents = pgTable(
(t) => [
uniqueIndex('client_id_user_id_unique').on(t.clientId, t.userId),
uniqueIndex('agents_slug_user_id_unique').on(t.slug, t.userId),
index('agents_user_id_idx').on(t.userId),
index('agents_title_idx').on(t.title),
index('agents_description_idx').on(t.description),
],
+1
View File
@@ -152,6 +152,7 @@ export const files = pgTable(
(table) => {
return {
fileHashIdx: index('file_hash_idx').on(table.fileHash),
userIdIdx: index('files_user_id_idx').on(table.userId),
parentIdIdx: index('files_parent_id_idx').on(table.parentId),
clientIdUnique: uniqueIndex('files_client_id_user_id_unique').on(
table.clientId,
+9
View File
@@ -2,6 +2,7 @@
import { DEFAULT_PREFERENCE } from '@lobechat/const';
import type { CustomPluginParams } from '@lobechat/types';
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
import { sql } from 'drizzle-orm';
import { boolean, index, jsonb, pgTable, primaryKey, text } from 'drizzle-orm/pg-core';
import { timestamps, timestamptz, varchar255 } from './_helpers';
@@ -49,6 +50,14 @@ export const users = pgTable(
(table) => ({
emailIdx: index('users_email_idx').on(table.email),
usernameIdx: index('users_username_idx').on(table.username),
createdAtIdx: index('users_created_at_idx').on(table.createdAt),
/**
* Partial index to speed up admin queries on banned users.
* Only rows with banned=true are indexed.
*/
bannedTrueCreatedAtIdx: index('users_banned_true_created_at_idx')
.on(table.createdAt)
.where(sql`${table.banned} = true`),
}),
);