Skip to content

Commit

Permalink
add filter
Browse files Browse the repository at this point in the history
  • Loading branch information
FoseFx committed May 20, 2024
1 parent f59026c commit 89719d1
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ func (p *Projection) onPropertyRuleListsUpdated(ctx context.Context, evt hwes.Ev

viewsQuery := p.viewsRepo.WithTx(tx)

removeFromAlwaysInclude := hwutil.SliceToSet(payload.RemoveFromAlwaysInclude)
removeFromDontAlwaysInclude := hwutil.SliceToSet(payload.RemoveFromDontAlwaysInclude)

appendToAlwaysIncludeFiltered := hwutil.Filter(payload.AppendToAlwaysInclude, func(id uuid.UUID) bool {
// the intent of being in the "don't list" is stronger
// if an id is in both lists, it gets removed from the "always list"
_, inRemove := removeFromAlwaysInclude[id]
_, inRemoveFromDont := removeFromDontAlwaysInclude[id]

return !inRemove && inRemoveFromDont
})

mapper := func(dontAlwaysInclude bool) func(uuid.UUID) views_repo.AddToAlwaysIncludeParams {
return func(propertyId uuid.UUID) views_repo.AddToAlwaysIncludeParams {
return views_repo.AddToAlwaysIncludeParams{
Expand All @@ -159,7 +171,7 @@ func (p *Projection) onPropertyRuleListsUpdated(ctx context.Context, evt hwes.Ev
}
}

appendToAlwaysInclude := hwutil.Map(payload.AppendToAlwaysInclude, mapper(false))
appendToAlwaysInclude := hwutil.Map(appendToAlwaysIncludeFiltered, mapper(false))
appendToDontAlwaysInclude := hwutil.Map(payload.AppendToDontAlwaysInclude, mapper(true))
toAppend := slices.Concat(appendToAlwaysInclude, appendToDontAlwaysInclude)

Expand Down

0 comments on commit 89719d1

Please sign in to comment.