Skip to content

Commit

Permalink
optimize-requests
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <[email protected]>
  • Loading branch information
EtienneLt committed Oct 9, 2024
1 parent 1367739 commit ecd54b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public interface ModificationRepository extends JpaRepository<ModificationEntity
@Query(value = "SELECT new ModificationEntity(m.id, m.type, m.date, m.stashed, m.activated, m.messageType, m.messageValues) FROM ModificationEntity m WHERE m.group.id = ?1 order by m.modificationsOrder")
List<ModificationEntity> findAllBaseByGroupId(UUID uuid);

@Query(value = "SELECT new ModificationEntity(m.id, m.type, m.date, m.stashed, m.activated, m.messageType, m.messageValues) FROM ModificationEntity m WHERE m.group.id = ?1 order by m.modificationsOrder desc")
List<ModificationEntity> findAllBaseByGroupIdReverse(UUID uuid);

@Query(value = "SELECT m FROM ModificationEntity m WHERE m.group.id = ?1 AND m.stashed = ?2 order by m.modificationsOrder")
List<ModificationEntity> findAllStashedByGroupId(@Param("groupId") UUID groupId, @Param("stashed") Boolean stashed);

Expand All @@ -37,6 +40,9 @@ public interface ModificationRepository extends JpaRepository<ModificationEntity
@Query(value = "SELECT m FROM ModificationEntity m WHERE m.id IN (?1) ORDER BY m.modificationsOrder")
List<ModificationEntity> findAllByIdIn(List<UUID> uuids);

@Query(value = "SELECT m FROM ModificationEntity m WHERE m.id IN (?1) ORDER BY m.modificationsOrder desc")
List<ModificationEntity> findAllByIdInReverse(List<UUID> uuids);

@Query(value = "SELECT cast(modifications_id AS VARCHAR) FROM tabular_modification_modifications WHERE tabular_modification_entity_id = :uuid ORDER BY modifications_order", nativeQuery = true)
List<UUID> findSubModificationIdsByTabularModificationIdOrderByModificationsOrder(UUID uuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,19 @@ public List<ModificationInfos> getModifications(UUID groupUuid, boolean onlyMeta
}

public List<ModificationInfos> getModificationsMetadata(UUID groupUuid, boolean onlyStashed) {
Stream<ModificationEntity> modificationEntityStream = modificationRepository
.findAllBaseByGroupId(getModificationGroup(groupUuid).getId())
.stream();
if (onlyStashed) {
List<ModificationInfos> stashedModification = modificationEntityStream.filter(m -> m.getStashed())
return modificationRepository
.findAllBaseByGroupIdReverse(getModificationGroup(groupUuid).getId())
.stream()
.filter(ModificationEntity::getStashed)
.map(this::getModificationInfos)
.collect(Collectors.toList());
Collections.reverse(stashedModification);
return stashedModification;
} else {
return modificationEntityStream
.map(this::getModificationInfos)
.collect(Collectors.toList());
return modificationRepository
.findAllBaseByGroupId(getModificationGroup(groupUuid).getId())
.stream()
.map(this::getModificationInfos)
.collect(Collectors.toList());
}
}

Expand Down Expand Up @@ -450,11 +450,10 @@ public void reorderNetworkModifications(UUID groupId, Boolean stashed) {
@Transactional
public void restoreNetworkModifications(@NonNull List<UUID> modificationUuids, int unStashedSize) {
int modificationOrder = unStashedSize;
List<ModificationEntity> modifications = modificationRepository.findAllByIdIn(modificationUuids);
List<ModificationEntity> modifications = modificationRepository.findAllByIdInReverse(modificationUuids);
if (modifications.size() != modificationUuids.size()) {
throw new NetworkModificationException(MODIFICATION_NOT_FOUND);
}
Collections.reverse(modifications);
for (ModificationEntity modification : modifications) {
modification.setStashed(false);
modification.setModificationsOrder(modificationOrder++);
Expand Down

0 comments on commit ecd54b5

Please sign in to comment.