mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: Minor rbac memory optimization (#7391)
* test: Add benchmark for static rbac roles * static roles should only be allocated once * A unit test that modifies the ast value should not mess with the globals * Cache subject AST values to avoid reallocating slices
This commit is contained in:
@ -49,6 +49,20 @@ type Subject struct {
|
||||
Roles ExpandableRoles
|
||||
Groups []string
|
||||
Scope ExpandableScope
|
||||
|
||||
// cachedASTValue is the cached ast value for this subject.
|
||||
cachedASTValue ast.Value
|
||||
}
|
||||
|
||||
// WithCachedASTValue can be called if the subject is static. This will compute
|
||||
// the ast value once and cache it for future calls.
|
||||
func (s Subject) WithCachedASTValue() Subject {
|
||||
tmp := s
|
||||
v, err := tmp.regoValue()
|
||||
if err == nil {
|
||||
tmp.cachedASTValue = v
|
||||
}
|
||||
return tmp
|
||||
}
|
||||
|
||||
func (s Subject) Equal(b Subject) bool {
|
||||
|
Reference in New Issue
Block a user