(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
This commit is contained in:
George Gevoian 2024-10-08 12:52:57 -04:00
parent 8402cccd7e
commit c824964152

View File

@ -4326,8 +4326,10 @@ export class HomeDBManager extends EventEmitter {
}); });
const workspace: Workspace = this.unwrapQueryResult(await verifyEntity(wsQuery)); const workspace: Workspace = this.unwrapQueryResult(await verifyEntity(wsQuery));
workspace.removedAt = removedAt; workspace.removedAt = removedAt;
const data = await manager.save(workspace); await manager.createQueryBuilder()
return {status: 200, data}; .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); await this._checkRoomForAnotherDoc(doc.workspace, manager);
} }
doc.removedAt = removedAt; doc.removedAt = removedAt;
const data = await manager.save(doc); await manager.createQueryBuilder()
return {status: 200, data}; .update(Document).set({removedAt}).where({id: doc.id})
.execute();
return {status: 200, data: doc};
}); });
} }