From c824964152fd597f73111fe851f76c80f4dda0df Mon Sep 17 00:00:00 2001 From: George Gevoian Date: Tue, 8 Oct 2024 12:52:57 -0400 Subject: [PATCH] (core) Fix TypeORM failure when unremoving entities Summary: When `save` was called without any modifications to the entity, TypeORM would throw an error. This could sometimes occur if an entity was unremoved by two different clients with the same application state. We now avoid calling `save` if a document or workspace is already unremoved. Test Plan: Manual. Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D4365 --- app/gen-server/lib/homedb/HomeDBManager.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/gen-server/lib/homedb/HomeDBManager.ts b/app/gen-server/lib/homedb/HomeDBManager.ts index 58e6a561..a5acfaa4 100644 --- a/app/gen-server/lib/homedb/HomeDBManager.ts +++ b/app/gen-server/lib/homedb/HomeDBManager.ts @@ -4326,8 +4326,10 @@ export class HomeDBManager extends EventEmitter { }); const workspace: Workspace = this.unwrapQueryResult(await verifyEntity(wsQuery)); workspace.removedAt = removedAt; - const data = await manager.save(workspace); - return {status: 200, data}; + await manager.createQueryBuilder() + .update(Workspace).set({removedAt}).where({id: workspace.id}) + .execute(); + return {status: 200, data: workspace}; }); } @@ -4347,8 +4349,10 @@ export class HomeDBManager extends EventEmitter { await this._checkRoomForAnotherDoc(doc.workspace, manager); } doc.removedAt = removedAt; - const data = await manager.save(doc); - return {status: 200, data}; + await manager.createQueryBuilder() + .update(Document).set({removedAt}).where({id: doc.id}) + .execute(); + return {status: 200, data: doc}; }); }