Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8008de

Browse files
authored
chore: Optimize Filter() for small lists (#4282)
1 parent69c73b2 commitd8008de

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

‎coderd/rbac/authz.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,26 @@ func Filter[O Objecter](ctx context.Context, auth Authorizer, subjID string, sub
3939
returnobjects,nil
4040
}
4141
objectType:=objects[0].RBACObject().Type
42-
4342
filtered:=make([]O,0)
43+
44+
// Running benchmarks on this function, it is **always** faster to call
45+
// auth.ByRoleName on <10 objects. This is because the overhead of
46+
// 'PrepareByRoleName'. Once we cross 10 objects, then it starts to become
47+
// faster
48+
iflen(objects)<10 {
49+
for_,o:=rangeobjects {
50+
rbacObj:=o.RBACObject()
51+
ifrbacObj.Type!=objectType {
52+
returnnil,xerrors.Errorf("object types must be uniform across the set (%s), found %s",objectType,rbacObj)
53+
}
54+
err:=auth.ByRoleName(ctx,subjID,subjRoles,scope,action,o.RBACObject())
55+
iferr==nil {
56+
filtered=append(filtered,o)
57+
}
58+
}
59+
returnfiltered,nil
60+
}
61+
4462
prepared,err:=auth.PrepareByRoleName(ctx,subjID,subjRoles,scope,action,objectType)
4563
iferr!=nil {
4664
returnnil,xerrors.Errorf("prepare: %w",err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp