Skip to content

Commit

Permalink
perf: claire's review
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeperrault authored and maximeperraultdev committed Sep 3, 2024
1 parent 3bdaa98 commit 460757e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class JpaReportingRepository(
targetDetail.externalReferenceNumber,
targetDetail.vesselName,
targetDetail.operatorName,
targetDetail.size.toString(),
targetDetail.vesselType?.name,
).any { field ->
!field.isNullOrBlank() && normalizeField(field)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,28 @@ interface IDBMissionRepository : JpaRepository<MissionModel, Int> {
seaFronts: List<String>? = emptyList(),
startedAfter: Instant,
startedBefore: Instant?,
// searchQuery: String,
): List<MissionModel>

@EntityGraph(value = "MissionModel.fullLoad", type = EntityGraph.EntityGraphType.LOAD)
@Query(
value = """
SELECT mm
FROM MissionModel mm
SELECT mission
FROM MissionModel mission
WHERE
mm.isDeleted = false AND
mm.id IN :ids
ORDER BY mm.startDateTimeUtc DESC
mission.isDeleted = false AND
mission.id IN :ids
ORDER BY mission.startDateTimeUtc DESC
""",
)
fun findNotDeletedByIds(ids: List<Int>): List<MissionModel>

@EntityGraph(value = "MissionModel.fullLoad", type = EntityGraph.EntityGraphType.LOAD)
@Query("SELECT mm FROM MissionModel mm JOIN mm.controlUnits mmcu WHERE mmcu.unit.id = :controlUnitId")
@Query("SELECT mission FROM MissionModel mission JOIN mission.controlUnits missionControlUnitResources WHERE missionControlUnitResources.unit.id = :controlUnitId")
fun findByControlUnitId(controlUnitId: Int): List<MissionModel>

@EntityGraph(value = "MissionModel.fullLoad", type = EntityGraph.EntityGraphType.LOAD)
@Query(
"SELECT mm FROM MissionModel mm JOIN mm.controlResources mmcr WHERE mmcr.resource.id = :controlUnitResourceId",
"SELECT mission FROM MissionModel mission JOIN mission.controlResources missionControlUnitResources WHERE missionControlUnitResources.resource.id = :controlUnitResourceId",
)
fun findByControlUnitResourceId(controlUnitResourceId: Int): List<MissionModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,51 +103,51 @@ interface IDBReportingRepository : JpaRepository<ReportingModel, Int> {
@EntityGraph(value = "ReportingModel.fullLoad", type = EntityGraph.EntityGraphType.LOAD)
@Query(
"""
SELECT DISTINCT r
FROM ReportingModel r
WHERE r.isDeleted IS FALSE
AND r.createdAt >= CAST(CAST(:startedAfter as text) AS timestamp)
AND (CAST(CAST(:startedBefore as text) AS timestamp) IS NULL OR r.createdAt <= CAST(CAST(:startedBefore as text) AS timestamp))
AND (:seaFronts IS NULL OR r.seaFront IN (:seaFronts))
SELECT DISTINCT reporting
FROM ReportingModel reporting
WHERE reporting.isDeleted = false
AND reporting.createdAt >= CAST(CAST(:startedAfter as text) AS timestamp)
AND (CAST(CAST(:startedBefore as text) AS timestamp) IS NULL OR reporting.createdAt <= CAST(CAST(:startedBefore as text) AS timestamp))
AND (:seaFronts IS NULL OR reporting.seaFront IN (:seaFronts))
AND (:sourcesType IS NULL OR EXISTS (
SELECT 1
FROM ReportingSourceModel rs
WHERE rs.reporting.id = r.id
AND rs.sourceType IN (:sourcesType)
FROM ReportingSourceModel reportingSource
WHERE reportingSource.reporting.id = reporting.id
AND reportingSource.sourceType IN (:sourcesType)
))
AND (:reportingType IS NULL OR r.reportType IN (:reportingType))
AND (:reportingType IS NULL OR reporting.reportType IN (:reportingType))
AND (:status IS NULL
OR (
'ARCHIVED' IN (:status) AND
(r.isArchived = true
OR r.validityEndTime < CURRENT_TIMESTAMP)
(reporting.isArchived = true
OR reporting.validityEndTime < CURRENT_TIMESTAMP)
)
OR (
'IN_PROGRESS' IN :status AND (
r.isArchived = false
AND r.validityEndTime >= CURRENT_TIMESTAMP
reporting.isArchived = false
AND reporting.validityEndTime >= CURRENT_TIMESTAMP
)
)
)
AND (:targetTypes IS NULL OR r.targetType IN (:targetTypes))
AND (:targetTypes IS NULL OR reporting.targetType IN (:targetTypes))
AND (:isAttachedToMission IS NULL
OR (
:isAttachedToMission = true AND (
r.mission.id IS NOT NULL
AND r.detachedFromMissionAtUtc IS NULL
reporting.mission.id IS NOT NULL
AND reporting.detachedFromMissionAtUtc IS NULL
)
)
OR (
:isAttachedToMission = false AND (
r.mission.id IS NULL
reporting.mission.id IS NULL
OR (
r.mission.id IS NOT NULL
AND r.detachedFromMissionAtUtc IS NOT NULL
reporting.mission.id IS NOT NULL
AND reporting.detachedFromMissionAtUtc IS NOT NULL
)
)
)
)
ORDER BY r.reportingId DESC
ORDER BY reporting.reportingId DESC
""",
)
fun findAll(
Expand All @@ -166,9 +166,9 @@ interface IDBReportingRepository : JpaRepository<ReportingModel, Int> {
@Query(
value =
"""
SELECT r
FROM ReportingModel r
INNER JOIN ReportingSourceModel rs ON r.id = rs.reporting.id
SELECT reporting
FROM ReportingModel reporting
INNER JOIN ReportingSourceModel rs ON reporting.id = rs.reporting.id
WHERE rs.controlUnit.id = :controlUnitId
""",
)
Expand All @@ -179,9 +179,9 @@ interface IDBReportingRepository : JpaRepository<ReportingModel, Int> {
@Query(
value =
"""
SELECT r
FROM ReportingModel r
WHERE r.mission.id = :missionId
SELECT reporting
FROM ReportingModel reporting
WHERE reporting.mission.id = :missionId
""",
)
fun findByMissionId(
Expand Down

0 comments on commit 460757e

Please sign in to comment.