From 9b03db016cdfd2f6ba46cd14a8a519e8b7f201db Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 28 Jul 2026 17:44:16 -0400 Subject: [PATCH] fix: Recalculate memberships in the same transaction when moving doc (#13182) closes #13181 --- .../processors/DocumentMovedProcessor.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/server/queues/processors/DocumentMovedProcessor.ts b/server/queues/processors/DocumentMovedProcessor.ts index e1588746ba..f73fd52f0e 100644 --- a/server/queues/processors/DocumentMovedProcessor.ts +++ b/server/queues/processors/DocumentMovedProcessor.ts @@ -38,8 +38,8 @@ export default class DocumentMovedProcessor extends BaseProcessor { : [], ]); - await this.destroyUserMemberships(document.id); - await this.destroyGroupMemberships(document.id); + await this.destroyUserMemberships(document, transaction); + await this.destroyGroupMemberships(document, transaction); await this.recalculateUserMemberships( parentDocumentUserMemberships, @@ -54,27 +54,37 @@ export default class DocumentMovedProcessor extends BaseProcessor { }); } - private async destroyUserMemberships(documentId: string) { - const document = await Document.findByPk(documentId); - const childDocumentIds = await document.findAllChildDocumentIds(); + private async destroyUserMemberships( + document: Document, + transaction: Transaction + ) { + const childDocumentIds = await document.findAllChildDocumentIds(undefined, { + transaction, + }); await UserMembership.destroy({ where: { sourceId: { [Op.ne]: null }, - documentId: [...childDocumentIds, documentId], + documentId: [...childDocumentIds, document.id], }, + transaction, }); } - private async destroyGroupMemberships(documentId: string) { - const document = await Document.findByPk(documentId); - const childDocumentIds = await document.findAllChildDocumentIds(); + private async destroyGroupMemberships( + document: Document, + transaction: Transaction + ) { + const childDocumentIds = await document.findAllChildDocumentIds(undefined, { + transaction, + }); await GroupMembership.destroy({ where: { sourceId: { [Op.ne]: null }, - documentId: [...childDocumentIds, documentId], + documentId: [...childDocumentIds, document.id], }, + transaction, }); }