Skip to content

chore: fetch templates by id without lock in dbfake #6351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore: fetch templates by id without lock in dbfake
  • Loading branch information
kylecarbs committed Feb 26, 2023
commit 38684d1afd85f55451dd66b7a1ac5d020c313e2d
8 changes: 6 additions & 2 deletions coderd/database/dbfake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ func (q *fakeQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg database.
}

if arg.TemplateName != "" {
template, err := q.GetTemplateByID(ctx, workspace.TemplateID)
template, err := q.getTemplateByIDNoLock(ctx, workspace.TemplateID)
if err == nil && !strings.EqualFold(arg.TemplateName, template.Name) {
continue
}
Expand Down Expand Up @@ -1617,10 +1617,14 @@ func (q *fakeQuerier) ParameterValues(_ context.Context, arg database.ParameterV
return parameterValues, nil
}

func (q *fakeQuerier) GetTemplateByID(_ context.Context, id uuid.UUID) (database.Template, error) {
func (q *fakeQuerier) GetTemplateByID(ctx context.Context, id uuid.UUID) (database.Template, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

return q.getTemplateByIDNoLock(ctx, id)
}

func (q *fakeQuerier) getTemplateByIDNoLock(_ context.Context, id uuid.UUID) (database.Template, error) {
for _, template := range q.templates {
if template.ID == id {
return template, nil
Expand Down