Skip to content

Commit

Permalink
fix: branch update not deleting old branches
Browse files Browse the repository at this point in the history
Because, `Ix.deleteIx` only deletes at most one item!
  • Loading branch information
srid committed Feb 6, 2025
1 parent 33bb3dd commit 2d5abe8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Vira/State/Acid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ setRepoBranchesA :: RepoName -> Map BranchName CommitID -> Update ViraState ()
setRepoBranchesA repo branches = do
modify $ \s ->
let
otherBranches = s.branches & Ix.deleteIx repo
otherRepoBranches = traceShowId $ s.branches & deleteIxMulti repo
repoBranches = Map.toList branches <&> uncurry (Branch repo)
in
s
{ branches = Ix.insertList repoBranches otherBranches
{ branches = Ix.insertList repoBranches otherRepoBranches
}

-- | Get all jobs of a repo's branch in descending order
Expand Down Expand Up @@ -132,6 +132,16 @@ markRunningJobsAsStaleA = do
jobUpdateStatusA job.jobId JobKilled
_ -> pass

-- | Like `Ix.deleteIx`, but works for multiple items
deleteIxMulti ::
(Ix.Indexable ixs a, Ix.IsIndexOf ix ixs) =>
ix ->
Ix.IxSet ixs a ->
Ix.IxSet ixs a
deleteIxMulti r rels =
let candidates = Ix.toList $ Ix.getEQ r rels
in flipfoldl' Ix.delete rels candidates

$( makeAcidic
''ViraState
[ 'setAllReposA
Expand Down

0 comments on commit 2d5abe8

Please sign in to comment.