Skip to content

Commit

Permalink
refactor: usea updateIxMulti
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Feb 6, 2025
1 parent 2d5abe8 commit 72b5f4e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Vira/State/Acid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ setRepoBranchesA :: RepoName -> Map BranchName CommitID -> Update ViraState ()
setRepoBranchesA repo branches = do
modify $ \s ->
let
otherRepoBranches = traceShowId $ s.branches & deleteIxMulti repo
repoBranches = Map.toList branches <&> uncurry (Branch repo)
in
s
{ branches = Ix.insertList repoBranches otherRepoBranches
{ branches = updateIxMulti repo (Ix.fromList repoBranches) s.branches
}

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

-- | Like `Ix.updateIx`, but works for multiple items.
updateIxMulti ::
(Ix.IsIndexOf ix ixs, Ix.Indexable ixs a) =>
ix ->
Ix.IxSet ixs a ->
Ix.IxSet ixs a ->
Ix.IxSet ixs a
updateIxMulti r new rels =
let old = rels @= r
deleteMany = foldr Ix.delete
in new `Ix.union` (rels `deleteMany` old)

-- | Like `Ix.deleteIx`, but works for multiple items
deleteIxMulti ::
(Ix.Indexable ixs a, Ix.IsIndexOf ix ixs) =>
Expand Down

0 comments on commit 72b5f4e

Please sign in to comment.