From 0c2950a19b5cdf1fab8bd59831438846943b91f9 Mon Sep 17 00:00:00 2001 From: Florent MILLOT <75525996+flomillot@users.noreply.github.com> Date: Thu, 4 Jan 2024 10:38:52 +0100 Subject: [PATCH] Optimize SQL queries when getting tabular modification of generators (#411) Fix the n+1 problem when building a node with generators tabular modification. We just have to call the right method already implemented. Signed-off-by: Florent MILLOT --- .../server/repositories/NetworkModificationRepository.java | 4 ++-- .../TabularGeneratorModificationsTest.java | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java index cb12d47ee..aa87d035b 100644 --- a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java +++ b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java @@ -177,10 +177,10 @@ public List getModificationsInfos(List groupUuids, bool Stream modificationEntity = groupUuids.stream().flatMap(this::getModificationEntityStream); if (onlyStashed) { return modificationEntity.filter(m -> m.getStashed() == onlyStashed) - .map(ModificationEntity::toModificationInfos) + .map(this::getModificationInfos) .collect(Collectors.toList()); } else { - return modificationEntity.map(ModificationEntity::toModificationInfos) + return modificationEntity.map(this::getModificationInfos) .collect(Collectors.toList()); } } diff --git a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularGeneratorModificationsTest.java b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularGeneratorModificationsTest.java index 4e9fa82fd..f5088048a 100644 --- a/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularGeneratorModificationsTest.java +++ b/src/test/java/org/gridsuite/modification/server/modifications/tabularmodifications/TabularGeneratorModificationsTest.java @@ -120,6 +120,13 @@ public void testCheckSqlRequestsCount() throws Exception { .andReturn(); // We check that the request count is not dependent on the number of sub modifications of the tabular modification (the JPA N+1 problem is correctly solved) assertSelectCount(3); + reset(); + + // We get the modifications of the group (so the 2 tabular modifications) + mockMvc.perform(get("/v1/groups/{groupUuid}/network-modifications", getGroupId())) + .andExpect(status().isOk()); + // We check that the request count is not dependent on the number of sub modifications of the tabular modification (the JPA N+1 problem is correctly solved) + assertSelectCount(6); } @Test