From 7275d417b2c9b41b55b4f2b9b527de9a8c833476 Mon Sep 17 00:00:00 2001 From: liuyi Date: Thu, 19 Oct 2023 16:12:57 +0800 Subject: [PATCH] fix(server): avoid workspace subdoc guid conflict (#4664) --- packages/backend/server/src/modules/doc/manager.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/backend/server/src/modules/doc/manager.ts b/packages/backend/server/src/modules/doc/manager.ts index 93be879a88..0dec55d1da 100644 --- a/packages/backend/server/src/modules/doc/manager.ts +++ b/packages/backend/server/src/modules/doc/manager.ts @@ -434,6 +434,10 @@ export class DocManager let lastTurnCount = 100; while (lastTurnCount === 100) { const docs = await this.db.snapshot.findMany({ + select: { + workspaceId: true, + id: true, + }, skip: turn * 100, take: 100, orderBy: { @@ -446,6 +450,12 @@ export class DocManager const docId = new DocID(doc.id, doc.workspaceId); if (docId && !docId.isWorkspace && docId.guid !== doc.id) { + await this.db.snapshot.deleteMany({ + where: { + id: docId.guid, + workspaceId: doc.workspaceId, + }, + }); await this.db.snapshot.update({ where: { id_workspaceId: {