feat: 更新会话列表查询,按更新时间降序排序

This commit is contained in:
suyao 2025-09-23 17:54:48 +08:00
parent ede2b75cd0
commit a0193451a9
No known key found for this signature in database

View File

@ -8,7 +8,7 @@ import {
type UpdateSessionRequest, type UpdateSessionRequest,
UpdateSessionResponse UpdateSessionResponse
} from '@types' } from '@types'
import { and, count, eq, type SQL } from 'drizzle-orm' import { and, count, desc, eq, type SQL } from 'drizzle-orm'
import { BaseService } from '../BaseService' import { BaseService } from '../BaseService'
import { agentsTable, type InsertSessionRow, type SessionRow, sessionsTable } from '../database/schema' import { agentsTable, type InsertSessionRow, type SessionRow, sessionsTable } from '../database/schema'
@ -137,8 +137,12 @@ export class SessionService extends BaseService {
const total = totalResult[0].count const total = totalResult[0].count
// Build list query with pagination // Build list query with pagination - sort by updated_at descending (latest first)
const baseQuery = this.database.select().from(sessionsTable).where(whereClause).orderBy(sessionsTable.created_at) const baseQuery = this.database
.select()
.from(sessionsTable)
.where(whereClause)
.orderBy(desc(sessionsTable.updated_at))
const result = const result =
options.limit !== undefined options.limit !== undefined