mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 19:16:29 +08:00
feat(server): allow drop session (#13650)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Ensures deleted sessions and their messages are consistently cleaned up, preventing lingering pinned or partially removed items. * **Refactor** * Streamlined session cleanup into a single bulk operation for improved reliability and performance during deletions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -459,27 +459,19 @@ export class CopilotSessionModel extends BaseModel {
|
||||
docId: options.docId,
|
||||
deletedAt: null,
|
||||
},
|
||||
select: { id: true, prompt: true },
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
const sessionIds = sessions.map(({ id }) => id);
|
||||
// cleanup all messages
|
||||
await this.db.aiSessionMessage.deleteMany({
|
||||
where: { sessionId: { in: sessionIds } },
|
||||
});
|
||||
|
||||
// only mark action session as deleted
|
||||
// chat session always can be reuse
|
||||
const actionIds = sessions
|
||||
.filter(({ prompt }) => !!prompt.action)
|
||||
.map(({ id }) => id);
|
||||
|
||||
// 标记 action session 为已删除
|
||||
if (actionIds.length > 0) {
|
||||
await this.db.aiSession.updateMany({
|
||||
where: { id: { in: actionIds } },
|
||||
data: { pinned: false, deletedAt: new Date() },
|
||||
});
|
||||
}
|
||||
await this.db.aiSession.updateMany({
|
||||
where: { id: { in: sessionIds } },
|
||||
data: { pinned: false, deletedAt: new Date() },
|
||||
});
|
||||
|
||||
return sessionIds;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user