MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetUserGroupsSnapshot

Method GetUserGroupsSnapshot

backend/store/group.go:363–388  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

361// userName format is "users/{email}".
362// Trades consistency for performance.
363func (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.

Callers 1

GetUserGroupsMethod · 0.80

Calls 5

ListGroupsMethod · 0.95
FormatGroupEmailFunction · 0.92
getMemberGroupsCacheKeyFunction · 0.85
GetMethod · 0.80
GetMembersMethod · 0.45

Tested by

no test coverage detected