From bb12f96a6fd775199f72fc259b9c3747974a6608 Mon Sep 17 00:00:00 2001 From: nk-coding Date: Tue, 10 Sep 2024 04:50:10 +0200 Subject: [PATCH] performance improvement for update project --- .../gropius/service/architecture/LayoutService.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/gropius/service/architecture/LayoutService.kt b/core/src/main/kotlin/gropius/service/architecture/LayoutService.kt index 4091b25c..6f35efe2 100644 --- a/core/src/main/kotlin/gropius/service/architecture/LayoutService.kt +++ b/core/src/main/kotlin/gropius/service/architecture/LayoutService.kt @@ -46,9 +46,13 @@ class LayoutService( layout: Layout, input: UpdateLayoutInput, batchUpdater: NodeBatchUpdater, ) { val cache = batchUpdater.cache + val newLayouts = input.relationPartnerLayouts.orElse(emptyList()) + if (newLayouts.isEmpty()) { + return + } val relationPartnerLayouts = layout.relationPartnerLayouts(cache).associateBy { it.relationPartner(cache).value.rawId!! } - input.relationPartnerLayouts.orElse(emptyList()).forEach { + newLayouts.forEach { if (it.layout != null) { val existingLayout = relationPartnerLayouts[it.relationPartner.value] if (existingLayout == null) { @@ -80,8 +84,12 @@ class LayoutService( layout: Layout, input: UpdateLayoutInput, batchUpdater: NodeBatchUpdater, ) { val cache = batchUpdater.cache + val newLayouts = input.relationLayouts.orElse(emptyList()) + if (newLayouts.isEmpty()) { + return + } val relationLayouts = layout.relationLayouts(cache).associateBy { it.relation(cache).value.rawId!! } - input.relationLayouts.orElse(emptyList()).forEach { + newLayouts.forEach { if (it.layout != null) { val existingLayout = relationLayouts[it.relation.value] val xCoordinates = it.layout.points.map { point -> point.x }.toIntArray()