Skip to content

Commit

Permalink
Merge pull request #464 from uselagoon/unlimited-cache
Browse files Browse the repository at this point in the history
fix: avoid spurious rate limit
  • Loading branch information
smlx authored Aug 6, 2024
2 parents dda6f2e + 6d773d0 commit 3807745
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/keycloak/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ func (c *Client) rawGroups(ctx context.Context) ([]byte, error) {
func (c *Client) GroupNameGroupIDMap(
ctx context.Context,
) (map[string]string, error) {
// rate limit keycloak API access
if err := c.limiter.Wait(ctx); err != nil {
return nil, fmt.Errorf("couldn't wait for limiter: %v", err)
}
// prefer to use cached value
if groupNameGroupIDMap, ok := c.groupCache.Get(); ok {
return groupNameGroupIDMap, nil
}
// otherwise get data from keycloak
if err := c.limiter.Wait(ctx); err != nil {
return nil, fmt.Errorf("couldn't wait for limiter: %v", err)
}
data, err := c.rawGroups(ctx)
if err != nil {
return nil, fmt.Errorf("couldn't get groups from Keycloak API: %v", err)
Expand Down

0 comments on commit 3807745

Please sign in to comment.