mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: drop N+1 db query on template ACL available (#25465)
Fixes [PLAT-149](https://linear.app/codercom/issue/PLAT-149/template-permissions-search-is-extremely-slow-with-many-groups). `/acl/available` ran a db query per group. A deployment with >5,000 groups made this route extremely slow.
This commit is contained in:
+13
-3
@@ -375,9 +375,19 @@ func (c *Client) UpdateTemplateACL(ctx context.Context, templateID uuid.UUID, re
|
||||
return nil
|
||||
}
|
||||
|
||||
// TemplateACLAvailable returns available users + groups that can be assigned template perms
|
||||
func (c *Client) TemplateACLAvailable(ctx context.Context, templateID uuid.UUID) (ACLAvailable, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templates/%s/acl/available", templateID), nil)
|
||||
// TemplateACLAvailable returns available users + groups that can be assigned
|
||||
// template perms. The optional req controls the q/limit/offset query
|
||||
// parameters applied server-side; pass codersdk.UsersRequest{} when no
|
||||
// filtering is desired.
|
||||
func (c *Client) TemplateACLAvailable(ctx context.Context, templateID uuid.UUID, req UsersRequest) (ACLAvailable, error) {
|
||||
res, err := c.Request(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
fmt.Sprintf("/api/v2/templates/%s/acl/available", templateID),
|
||||
nil,
|
||||
req.Pagination.asRequestOption(),
|
||||
req.asRequestOption(),
|
||||
)
|
||||
if err != nil {
|
||||
return ACLAvailable{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user