Repository navigation
Conversation
Version recalculation now updates only `latestVersion` by module ID. The integration test commits a description edit after loading the refresh snapshot, then checks that both the edit and the newly discovered version are present after recalculation. Fixes terrakube-io#4053
Macbet
left a comment
There was a problem hiding this comment.
Thanks for the fix! The core change (switching ModuleLatestVersion to a targeted @Transactional @Modifying UPDATE and not mutating the Module entity) looks good and CI is green.
A few small things to clean up before approving and merging:
-
Align comments with
main's refresh flow
Onmain,ModuleRefreshWorkerno longer holds aModuleentity acrossls-remote(loadTargetreturns aModuleRefreshTargetDTO, andModuleRefreshTransactions.recordSuccessacquires the row lock viamarkRefreshedbefore loadingModule). The detached/stale entity overwrite onmainhappens viaModuleVersionManageHook(POSTCOMMIT, outside a transaction) or any caller holding a stale snapshot, while inrecordSuccessavoidingsave(module)keeps refreshes from bumpingupdatedDate/updatedBy.- Please update the comments in
ModuleRefreshTransactionsIntegrationTest#refreshKeepsADescriptionEditedWhileItRuns(and the PR description) so they reflectmainrather than the older 2.34.xModuleRefreshJobflow.
- Please update the comments in
-
Update now-outdated comments in the modified files
ModuleRepository.java(comment abovemarkRefreshed): remove(Module has @DynamicUpdate, so saving it later does not write these columns back)sincerecordSuccessno longer saves the entity.ModuleRefreshTransactionsIntegrationTest.java(successThatChangesLatestVersionKeepsTheComputedNextRefresh): updatewhich ModuleLatestVersion saves through the entitysince it now uses a targetedUPDATE.
-
Note why
module.setLatestVersion(...)is omitted
InModuleLatestVersion.java, please mention in the comment that leaving the entity untouched is intentional so a managedModuleisn't dirtied and flushed back at transaction commit. -
Clean up the
## Testingsection in the PR description
It currently contains contradictory lines ("timed out after 599 seconds", "all 20 pass", "did not run here").
(Optional nits): adding verifyNoMoreInteractions(moduleRepository) (or verify(moduleRepository, never()).save(any())) in ModuleLatestVersionTest and passing e to log.error(...) in ModuleLatestVersion's catch block would also be nice to have.
|
@Macbet thanks for the review, pushed 9758ed1 for all four points plus both nits.
|
What changed and why?
The API can accept an edit to a newly created module's description, then return the old description once a version recalculation runs. On
mainthe refresh worker no longer holds aModuleacrossls-remote(loadTargetreturns aModuleRefreshTarget, andModuleRefreshTransactions.recordSuccesstakes the row lock throughmarkRefreshedbefore it loads theModule). The stale overwrite comes fromModuleVersionManageHook, which recalculates POSTCOMMIT outside a transaction, or from any caller holding an older snapshot:ModuleLatestVersionsaved that snapshot, which wrote its old description over the edit.Version recalculation now updates only
latestVersionby module ID with a targetedUPDATE, and leaves theModuleentity untouched so a managed instance is not dirtied and flushed at commit. InrecordSuccess, not saving the entity also keeps refreshes from movingupdatedDate/updatedBy. The integration test commits a description edit after loading an older snapshot, then checks that both the edit and the newly discovered version are present after recalculation.Fixes #4053
Testing
mvn -B -q -pl api -Dtest=ModuleLatestVersionTest -Dsurefire.failIfNoSpecifiedTests=false testpasses locally on 9758ed1 (3 tests).ModuleRefreshTransactionsIntegrationTestruns in CI.Visual changes (if applicable)
No user-visible surface changes in this PR, so there is nothing to show.