Skip to content

Commit

Permalink
Optimize SQL queries when getting tabular modification of generators (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
flomillot authored Jan 4, 2024
1 parent 017f692 commit 0c2950a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ public List<ModificationInfos> getModificationsInfos(List<UUID> groupUuids, bool
Stream<ModificationEntity> 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0c2950a

Please sign in to comment.