-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optim get tabular modif #422
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
4ffe44f
to
24d7e72
Compare
…val for all tabulars Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
24d7e72
to
4858bea
Compare
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
…k-modification-server into optim_get_tabular_modif
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
069f21d
to
b7846eb
Compare
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
|
||
@EntityGraph(attributePaths = {"reactiveCapabilityCurvePoints"}, type = EntityGraph.EntityGraphType.LOAD) | ||
Set<GeneratorModificationEntity> findAllReactiveCapabilityCurvePointsByIdIn(List<UUID> ids); | ||
@Query(value = "SELECT cast(modifications_id as varchar) from tabular_modification_modifications where tabular_modification_entity_id= ?1", nativeQuery = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lack a space : tabular_modification_entity_id= ?1 => tabular_modification_entity_id = ?1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, I also put SQL keywords in capital letters to harmonize
|
||
private List<ModificationInfos> createBatteryModificationList(int qty) { | ||
List<ModificationInfos> modifications = new ArrayList<>(); | ||
for (int i = 0; i <= qty; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, IntStream.range(0, qty).map().toList() is more expressive, less error-prone than using loop with
Idem for others test classes
if (onlyStashed) { | ||
return modificationEntity.filter(m -> m.getStashed() == onlyStashed) | ||
return modificationEntities.filter(m -> m.getStashed() == onlyStashed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be replaced by ModificationEntity::getStashed as line 148???
/** | ||
* @author Joris Mancini <joris.mancini_externe at rte-france.com> | ||
*/ | ||
public class TabularModificationRepositoryException extends RuntimeException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have already NetworkModificationException, is necessary to create a new one?
Optional<ModificationEntity> optionalModificationEntity = modificationRepository.findById(modificationUuid); | ||
if (!optionalModificationEntity.isPresent()) { | ||
throw new NetworkModificationException(MODIFICATION_NOT_FOUND, modificationUuid.toString()); | ||
public ModificationInfos getModificationInfos(UUID modificationUuid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be as following to avoid throw the same exception when getModificationInfos return null
public ModificationInfos getModificationInfos(UUID modificationUuid) {
ModificationEntity modificationEntity = modificationRepository.findById(modificationUuid)
.orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, modificationUuid.toString()));
return getModificationInfos(modificationEntity);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be nice to find a way to combine those tests classes
It could make them easier to maintain
@Query(value = "SELECT cast(modifications_id as varchar) from tabular_modification_modifications where tabular_modification_entity_id= ?1", nativeQuery = true) | ||
List<UUID> findSubModificationsIds(UUID uuid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need native query here ? If it is to get "modifications_id" only, we could use JPA projections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the relation table is not defined explicitly we cannot query it directly through JPA, so either we do it with native query directly on the relation table or we go though JPA but we need to add join because to query on TabularModificationEnity. So, I'd rather keep this solution, though the join solution would be quite equally performant I think.
mockMvc.perform(get("/v1/groups/{groupUuid}/network-modifications", groupUuid)) | ||
.andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) | ||
.andReturn(); | ||
} | ||
|
||
public static void getModification(MockMvc mockMvc, UUID modificationUuid) throws Exception { | ||
mockMvc.perform(get("/v1/network-modifications/{uuid}", modificationUuid)) | ||
.andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) | ||
.andReturn(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we don't get the returned value, we don't need "andReturn()"
public interface BatteryModificationRepository extends JpaRepository<BatteryModificationEntity, UUID>, EagerNetworkModificationRepository<BatteryModificationEntity> { | ||
|
||
@Override | ||
@EntityGraph(attributePaths = {"reactiveCapabilityCurvePoints", "properties"}, type = EntityGraph.EntityGraphType.LOAD) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was not possible to fetch two distinct collections from the same entity in JPA, see below exception
"org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags"
.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) | ||
reset(); | ||
ApiUtils.getGroupModifications(mockMvc, getGroupId()); // Getting two tabular modifications with respectively one and three sub-modifications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this call grows in SQL count if we create more tabular modifications
it might not be linked to this PR though, we might have this behaviour with other modifications
Same for other concerned tests
List<ModificationInfos> modifications = new ArrayList<>(); | ||
for (int i = 0; i <= qty; i++) { | ||
modifications.add( | ||
BatteryModificationInfos.builder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be nice to add some "reactiveCapabilityCurvePoints" to this builder to cover the @entitygraph usage
Same for other concerned tests
No description provided.