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

Method GetRole

backend/store/role.go:122–137  ·  view source on GitHub ↗

GetRole returns a role by ID with strong/consistent reads (no cache).

(ctx context.Context, find *FindRoleMessage)

Source from the content-addressed store, hash-verified

120
121// GetRole returns a role by ID with strong/consistent reads (no cache).
122func (s *Store) GetRole(ctx context.Context, find *FindRoleMessage) (*RoleMessage, error) {
123 roles, err := s.ListRoles(ctx, find)
124 if err != nil {
125 return nil, err
126 }
127 if len(roles) == 0 {
128 return nil, nil
129 }
130 if len(roles) > 1 {
131 return nil, &common.Error{Code: common.Conflict, Err: errors.Errorf("found %d roles with filter %+v, expect 1", len(roles), find)}
132 }
133 role := roles[0]
134
135 s.rolesCache.Add(role.ResourceID, role)
136 return role, nil
137}
138
139// GetRoleSnapshot returns a role by ID with snapshot reads (with cache).
140// Trades consistency for performance.

Callers 1

GetRoleSnapshotMethod · 0.95

Calls 2

ListRolesMethod · 0.95
ErrorfMethod · 0.80

Tested by

no test coverage detected