GetUserGroupsSnapshot returns groups for a user with snapshot reads (with cache). userName format is "users/{email}". Trades consistency for performance.
(ctx context.Context, workspaceID string, userName string)
| 361 | // userName format is "users/{email}". |
| 362 | // Trades consistency for performance. |
| 363 | func (s *Store) GetUserGroupsSnapshot(ctx context.Context, workspaceID string, userName string) ([]string, error) { |
| 364 | if v, ok := s.memberGroupsCache.Get(getMemberGroupsCacheKey(workspaceID, userName)); ok { |
| 365 | return v, nil |
| 366 | } |
| 367 | |
| 368 | groups, err := s.ListGroups(ctx, &FindGroupMessage{Workspace: workspaceID}) |
| 369 | if err != nil { |
| 370 | return nil, err |
| 371 | } |
| 372 | |
| 373 | var userGroups []string |
| 374 | for _, group := range groups { |
| 375 | for _, m := range group.Payload.GetMembers() { |
| 376 | if m.Member == userName { |
| 377 | groupName := common.FormatGroupEmail(group.Email) |
| 378 | if group.Email == "" { |
| 379 | groupName = common.FormatGroupEmail(group.ID) |
| 380 | } |
| 381 | userGroups = append(userGroups, groupName) |
| 382 | break |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | s.memberGroupsCache.Add(getMemberGroupsCacheKey(workspaceID, userName), userGroups) |
| 387 | return userGroups, nil |
| 388 | } |
| 389 | |
| 390 | // GetGroupMembersSnapshot returns group members with snapshot reads (with cache). |
| 391 | // groupName format is "groups/{identifier}" where identifier can be an email or an ID. |
no test coverage detected