Skip to content

Commit

Permalink
update flow set latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Idil Haq Amir committed Mar 8, 2024
1 parent 445e70e commit a9f223d
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions core/appeal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -852,21 +851,17 @@ func (s *Service) getPoliciesMap(ctx context.Context) (map[string]map[uint]*doma
return nil, err
}

// make sure to sort policies with version asc
sort.Slice(policies, func(i, j int) bool {
return policies[i].Version < policies[j].Version
})

policiesMap := map[string]map[uint]*domain.Policy{}
for _, p := range policies {
id := p.ID
version := p.Version
if policiesMap[id] == nil {
policiesMap[id] = map[uint]*domain.Policy{}
}
policiesMap[id][version] = p
// always update the map 0 to each policy id to keep the latest policy
policiesMap[id][0] = p
policiesMap[id][p.Version] = p
// set policiesMap[id][0] to latest policy version
if policiesMap[id][0] == nil || p.Version > policiesMap[id][0].Version {
policiesMap[id][0] = p
}
}

return policiesMap, nil
Expand Down

0 comments on commit a9f223d

Please sign in to comment.