From 355cbae734b00ac1e7e6771e3d276a0892f1458e Mon Sep 17 00:00:00 2001 From: Nikolay Rykunov Date: Tue, 17 Sep 2024 17:57:07 +0200 Subject: [PATCH] [platform] Use upsert instead of handmade check for entity existence GitOrigin-RevId: 0f8da0b94d763d699c6768e755f6847599e5e615 --- platform/project/shared/src/ProjectEntitiesStorage.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/platform/project/shared/src/ProjectEntitiesStorage.kt b/platform/project/shared/src/ProjectEntitiesStorage.kt index 237dc3ae2e6d..fd4ba5855c44 100644 --- a/platform/project/shared/src/ProjectEntitiesStorage.kt +++ b/platform/project/shared/src/ProjectEntitiesStorage.kt @@ -47,14 +47,8 @@ abstract class ProjectEntitiesStorage { If it happens that the entity has not been found and the frontend creates a new one, Rhizome DB will perform a "rebase" which basically re-invokes the whole "change" block either on the backend or the frontend side. */ - val existing = entity(ProjectEntity.ProjectIdValue, projectId) - if (existing != null) { - existing - } - else { - ProjectEntity.new { - it[ProjectEntity.ProjectIdValue] = projectId - } + ProjectEntity.upsert(ProjectEntity.ProjectIdValue, projectId) { + it[ProjectEntity.ProjectIdValue] = projectId } } }