@@ -39,8 +39,26 @@ func Filter[O Objecter](ctx context.Context, auth Authorizer, subjID string, sub
39
39
return objects ,nil
40
40
}
41
41
objectType := objects [0 ].RBACObject ().Type
42
-
43
42
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
+ if len (objects )< 10 {
49
+ for _ ,o := range objects {
50
+ rbacObj := o .RBACObject ()
51
+ if rbacObj .Type != objectType {
52
+ return nil ,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
+ if err == nil {
56
+ filtered = append (filtered ,o )
57
+ }
58
+ }
59
+ return filtered ,nil
60
+ }
61
+
44
62
prepared ,err := auth .PrepareByRoleName (ctx ,subjID ,subjRoles ,scope ,action ,objectType )
45
63
if err != nil {
46
64
return nil ,xerrors .Errorf ("prepare: %w" ,err )