Skip to content
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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Optim get tabular modif #422

wants to merge 20 commits into from

Conversation

etiennehomer
Copy link
Contributor

No description provided.

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>
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>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
Signed-off-by: Etienne Homer <etiennehomer@gmail.com>
@etiennehomer etiennehomer changed the title [WIP] Optim get tabular modif Optim get tabular modif Feb 2, 2024
@TheMaskedTurtle TheMaskedTurtle force-pushed the optim_get_tabular_modif branch from 4ffe44f to 24d7e72 Compare February 5, 2024 17:14
…val for all tabulars

Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
@TheMaskedTurtle TheMaskedTurtle force-pushed the optim_get_tabular_modif branch from 24d7e72 to 4858bea Compare February 5, 2024 17:52
TheMaskedTurtle and others added 5 commits February 6, 2024 10:25
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>
@TheMaskedTurtle TheMaskedTurtle force-pushed the optim_get_tabular_modif branch from 069f21d to b7846eb Compare February 6, 2024 11:23
Copy link

sonarqubecloud bot commented Feb 6, 2024

@klesaulnier klesaulnier self-requested a review February 7, 2024 14:46
@thangqp thangqp self-requested a review February 8, 2024 08:20

@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)
Copy link
Contributor

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

Copy link
Contributor

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++) {
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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) {
Copy link
Contributor

@thangqp thangqp Feb 8, 2024

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);
    }

Copy link
Contributor

@klesaulnier klesaulnier left a 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

Comment on lines +30 to +31
@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);
Copy link
Contributor

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

Copy link
Contributor

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.

Comment on lines +29 to +37
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();
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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()
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants