mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 06:06:33 +08:00
RBAC: Optimize permissions caching (#92412)
* Access control: Use composite cache key for team permissions * use composite key for teams * use cache for hotpath (getCachedUserPermissions) * fix linter * fix sorting --------- Co-authored-by: Jeff Levin <jeff@levinology.com>
This commit is contained in:
@ -2,12 +2,14 @@ package accesscontrol
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
)
|
||||
|
||||
func GetPermissionCacheKey(user identity.Requester) string {
|
||||
func GetUserPermissionCacheKey(user identity.Requester) string {
|
||||
return fmt.Sprintf("rbac-permissions-%s", user.GetCacheKey())
|
||||
}
|
||||
|
||||
@ -41,3 +43,12 @@ func GetBasicRolePermissionCacheKey(role string, orgID int64) string {
|
||||
func GetTeamPermissionCacheKey(teamID int64, orgID int64) string {
|
||||
return fmt.Sprintf("rbac-permissions-team-%d-%d", orgID, teamID)
|
||||
}
|
||||
|
||||
func GetTeamPermissionCompositeCacheKey(teamIds []int64, orgID int64) string {
|
||||
teams := make([]string, 0)
|
||||
for _, id := range teamIds {
|
||||
teams = append(teams, strconv.FormatInt(id, 10))
|
||||
}
|
||||
slices.Sort(teams)
|
||||
return fmt.Sprintf("rbac-permissions-team-%d-%s", orgID, strings.Join(teams, "-"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user