Skip to content

fix(perf): several backend performance improvements#1418

Open
lwih wants to merge 4 commits into
mainfrom
validation-perf
Open

fix(perf): several backend performance improvements#1418
lwih wants to merge 4 commits into
mainfrom
validation-perf

Conversation

@lwih

@lwih lwih commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

… new validation

@tristanrobert

tristanrobert commented Jun 18, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for frontend

Status Category Percentage Covered / Total
🔵 Lines 65.27% (🎯 40%) 3094 / 4740
🔵 Statements 63.96% (🎯 40%) 3358 / 5250
🔵 Functions 55.48% (🎯 40%) 1072 / 1932
🔵 Branches 59.26% (🎯 40%) 1452 / 2450
File CoverageNo changed files found.
Generated in workflow #4539 for commit eca0c86 by the Vitest Coverage Report Action

@lwih lwih changed the title fix(perf): avoid N+1 query problem on GetMissionDates introduced with… fix(perf): several backend performance improvements Jun 19, 2026
val actions = getEnvActionList(missionId = missionId)
// pass envActions when you don't want to refetch the whole mission
fun execute(missionId: Int, envActions: List<EnvActionEntity>? = null): List<MissionEnvActionEntity> {
val actions = envActions ?: getEnvMissionById2.execute(missionId = missionId)?.envActions ?: listOf()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En gros, pour chaque action, on allait chercher la mission pour avoir les actions alors qu'on les avait deja.
Autant réutiliser et fallback si necessaire

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

les actions sont dans le cache, c'est pas in appel couteux.
En terme de logique pure, Pour une meilleure lisibilité, un useCase
Compute(missionId: Int, envActions: List)

Et dans le parent, if(envActions) compute(id, envActions) else getComputeEnvActionListByMissionId(id)

Comment on lines +25 to +32
val statusActions = navActions
.filterIsInstance<MissionNavActionEntity>()
.filter { it.actionType == ActionType.STATUS && it.startDateTimeUtc != null }

return (computedEnvActions + navActions + fishActions)
.sortedByDescending { it.startDateTimeUtc }
.map { action ->
// compute action status
action.status = getStatusForAction.execute(missionId = missionId, actionStartDateTimeUtc = action.startDateTimeUtc)
action.status = computeStatus(action.startDateTimeUtc, statusActions)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ici pour le compute du status des actions, on a deja les actions donc autant les réutiliser alors qu'avant, on refaisait une db query à chaque fois

@Entity
@EntityListeners(AuditingEntityListener::class)
@Table(name = "agent_2")
@BatchSize(size = 20)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BatchSize, ca te permet de grouper des queries.
Prends l'exemple de l'équipage PAM qui va return 16 crew. Au lieu de faire 16 queries, ca fait 1 seule batch query

@OneToMany(fetch = FetchType.EAGER, cascade = [CascadeType.ALL], orphanRemoval = true)
@JoinColumn(name = "control_id")
@JsonIgnore
@BatchSize(size = 20)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pareil, batchSize ici aussi
Mais autant 20, ca se rapproche à peu près d'un crew de 16
mais ici, j'ai mis 20 alors qu'on fetch 4 controles, je sais pas torp. Au pire, on peut fine-tune plus tard

@lwih lwih force-pushed the validation-perf branch from 12852d8 to 6db114c Compare June 19, 2026 13:56
val portsCache = buildCache(ports, ticker, TimeUnit.DAYS, 7)
val natinfsCache = buildCache(natinfs, ticker, TimeUnit.DAYS, 7)
val resourcesCache = buildCache(resources, ticker, TimeUnit.DAYS, 1)
val servicesCache = buildCache(services, ticker, TimeUnit.DAYS, 1)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca, je sais pas ce que t'en penses mais pour les data assez statiques de notre db, on peut aussi les cacher sur un temps relativement court, ca aide un peu

@lwih lwih force-pushed the validation-perf branch from 6db114c to 5c16d12 Compare June 22, 2026 07:42
@MTES-MCT MTES-MCT deleted a comment from github-actions Bot Jun 22, 2026
@MTES-MCT MTES-MCT deleted a comment from github-actions Bot Jun 22, 2026
@MTES-MCT MTES-MCT deleted a comment from github-actions Bot Jun 22, 2026
@MTES-MCT MTES-MCT deleted a comment from github-actions Bot Jun 22, 2026
@MTES-MCT MTES-MCT deleted a comment from github-actions Bot Jun 22, 2026
@lwih lwih requested a review from xtiannyeto June 22, 2026 07:42
@github-actions

Copy link
Copy Markdown
Contributor
Overall Project 80.26% -0.02% 🍏
Files changed 88.59% 🍏

File Coverage
ProcessFishAction.kt 96.92% 🍏
ProcessEnvAction.kt 96.92% 🍏
GetComputeEnvActionListByMissionId.kt 93.44% -6.56% 🍏
GetComputeEnvMission.kt 89.72% 🍏
GetMissionAction.kt 86.18% -8.55% 🍏
AgentModel.kt 74.59% 🍏
AgentRoleModel.kt 73.23% 🍏
ServiceModel.kt 68.09% 🍏
ControlModel.kt 60.82% 🍏
InfractionModel.kt 49.72% 🍏

val actions = getEnvActionList(missionId = missionId)
// pass envActions when you don't want to refetch the whole mission
fun execute(missionId: Int, envActions: List<EnvActionEntity>? = null): List<MissionEnvActionEntity> {
val actions = envActions ?: getEnvMissionById2.execute(missionId = missionId)?.envActions ?: listOf()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

les actions sont dans le cache, c'est pas in appel couteux.
En terme de logique pure, Pour une meilleure lisibilité, un useCase
Compute(missionId: Int, envActions: List)

Et dans le parent, if(envActions) compute(id, envActions) else getComputeEnvActionListByMissionId(id)

@lwih lwih force-pushed the validation-perf branch 2 times, most recently from c586c35 to e370abc Compare June 24, 2026 15:42
@lwih lwih force-pushed the validation-perf branch from e370abc to cb74728 Compare June 25, 2026 10:35
@github-actions

Copy link
Copy Markdown
Contributor
Overall Project 80.26% -0.02% 🍏
Files changed 86.6% 🍏

File Coverage
ProcessFishAction.kt 97.01% 🍏
ProcessEnvAction.kt 97.01% 🍏
GetMissionAction.kt 85.11% -9.22% 🍏
AgentModel.kt 74.59% 🍏
AgentRoleModel.kt 73.23% 🍏
ServiceModel.kt 68.09% 🍏
ControlModel.kt 60.82% 🍏
InfractionModel.kt 49.72% 🍏

@lwih lwih force-pushed the validation-perf branch from cb74728 to eca0c86 Compare June 25, 2026 10:48
@github-actions

Copy link
Copy Markdown
Contributor
Overall Project 80.26% -0.02% 🍏
Files changed 86.6% 🍏

File Coverage
ProcessFishAction.kt 97.01% 🍏
ProcessEnvAction.kt 97.01% 🍏
GetMissionAction.kt 85.11% -9.22% 🍏
AgentModel.kt 74.59% 🍏
AgentRoleModel.kt 73.23% 🍏
ServiceModel.kt 68.09% 🍏
ControlModel.kt 60.82% 🍏
InfractionModel.kt 49.72% 🍏

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.

3 participants