Skip to content

fix(database): remove usage of String() for comparing UUIDs #4547

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
Oct 13, 2022
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
50 changes: 25 additions & 25 deletions coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (q *fakeQuerier) ParameterValue(_ context.Context, id uuid.UUID) (database.
defer q.mutex.Unlock()

for _, parameterValue := range q.parameterValues {
if parameterValue.ID.String() != id.String() {
if parameterValue.ID != id {
continue
}
return parameterValue, nil
Expand All @@ -253,7 +253,7 @@ func (q *fakeQuerier) DeleteParameterValueByID(_ context.Context, id uuid.UUID)
defer q.mutex.Unlock()

for index, parameterValue := range q.parameterValues {
if parameterValue.ID.String() != id.String() {
if parameterValue.ID != id {
continue
}
q.parameterValues[index] = q.parameterValues[len(q.parameterValues)-1]
Expand Down Expand Up @@ -495,7 +495,7 @@ func (q *fakeQuerier) GetUsersByIDs(_ context.Context, ids []uuid.UUID) ([]datab
users := make([]database.User, 0)
for _, user := range q.users {
for _, id := range ids {
if user.ID.String() != id.String() {
if user.ID != id {
continue
}
users = append(users, user)
Expand Down Expand Up @@ -716,7 +716,7 @@ func (q *fakeQuerier) GetWorkspaceByID(_ context.Context, id uuid.UUID) (databas
defer q.mutex.RUnlock()

for _, workspace := range q.workspaces {
if workspace.ID.String() == id.String() {
if workspace.ID == id {
return workspace, nil
}
}
Expand Down Expand Up @@ -787,7 +787,7 @@ func (q *fakeQuerier) GetWorkspaceAppsByAgentIDs(_ context.Context, ids []uuid.U
apps := make([]database.WorkspaceApp, 0)
for _, app := range q.workspaceApps {
for _, id := range ids {
if app.AgentID.String() == id.String() {
if app.AgentID == id {
apps = append(apps, app)
break
}
Expand Down Expand Up @@ -836,7 +836,7 @@ func (q *fakeQuerier) GetWorkspaceBuildByID(_ context.Context, id uuid.UUID) (da
defer q.mutex.RUnlock()

for _, history := range q.workspaceBuilds {
if history.ID.String() == id.String() {
if history.ID == id {
return history, nil
}
}
Expand All @@ -848,7 +848,7 @@ func (q *fakeQuerier) GetWorkspaceCountByUserID(_ context.Context, id uuid.UUID)
defer q.mutex.RUnlock()
var count int64
for _, workspace := range q.workspaces {
if workspace.OwnerID.String() == id.String() {
if workspace.OwnerID == id {
if workspace.Deleted {
continue
}
Expand All @@ -864,7 +864,7 @@ func (q *fakeQuerier) GetWorkspaceBuildByJobID(_ context.Context, jobID uuid.UUI
defer q.mutex.RUnlock()

for _, build := range q.workspaceBuilds {
if build.JobID.String() == jobID.String() {
if build.JobID == jobID {
return build, nil
}
}
Expand Down Expand Up @@ -953,7 +953,7 @@ func (q *fakeQuerier) GetWorkspaceBuildsByWorkspaceID(_ context.Context,
if workspaceBuild.CreatedAt.Before(params.Since) {
continue
}
if workspaceBuild.WorkspaceID.String() == params.WorkspaceID.String() {
if workspaceBuild.WorkspaceID == params.WorkspaceID {
history = append(history, workspaceBuild)
}
}
Expand Down Expand Up @@ -1006,7 +1006,7 @@ func (q *fakeQuerier) GetWorkspaceBuildByWorkspaceIDAndBuildNumber(_ context.Con
defer q.mutex.RUnlock()

for _, workspaceBuild := range q.workspaceBuilds {
if workspaceBuild.WorkspaceID.String() != arg.WorkspaceID.String() {
if workspaceBuild.WorkspaceID != arg.WorkspaceID {
continue
}
if workspaceBuild.BuildNumber != arg.BuildNumber {
Expand Down Expand Up @@ -1121,7 +1121,7 @@ func (q *fakeQuerier) GetTemplateByID(_ context.Context, id uuid.UUID) (database
defer q.mutex.RUnlock()

for _, template := range q.templates {
if template.ID.String() == id.String() {
if template.ID == id {
return template, nil
}
}
Expand Down Expand Up @@ -1217,7 +1217,7 @@ func (q *fakeQuerier) GetTemplateVersionsByTemplateID(_ context.Context, arg dat
defer q.mutex.RUnlock()

for _, templateVersion := range q.templateVersions {
if templateVersion.TemplateID.UUID.String() != arg.TemplateID.String() {
if templateVersion.TemplateID.UUID != arg.TemplateID {
continue
}
version = append(version, templateVersion)
Expand Down Expand Up @@ -1305,7 +1305,7 @@ func (q *fakeQuerier) GetTemplateVersionByID(_ context.Context, templateVersionI
defer q.mutex.RUnlock()

for _, templateVersion := range q.templateVersions {
if templateVersion.ID.String() != templateVersionID.String() {
if templateVersion.ID != templateVersionID {
continue
}
return templateVersion, nil
Expand All @@ -1318,7 +1318,7 @@ func (q *fakeQuerier) GetTemplateVersionByJobID(_ context.Context, jobID uuid.UU
defer q.mutex.RUnlock()

for _, templateVersion := range q.templateVersions {
if templateVersion.JobID.String() != jobID.String() {
if templateVersion.JobID != jobID {
continue
}
return templateVersion, nil
Expand All @@ -1332,7 +1332,7 @@ func (q *fakeQuerier) GetParameterSchemasByJobID(_ context.Context, jobID uuid.U

parameters := make([]database.ParameterSchema, 0)
for _, parameterSchema := range q.parameterSchemas {
if parameterSchema.JobID.String() != jobID.String() {
if parameterSchema.JobID != jobID {
continue
}
parameters = append(parameters, parameterSchema)
Expand Down Expand Up @@ -1685,7 +1685,7 @@ func (q *fakeQuerier) GetProvisionerDaemonByID(_ context.Context, id uuid.UUID)
defer q.mutex.RUnlock()

for _, provisionerDaemon := range q.provisionerDaemons {
if provisionerDaemon.ID.String() != id.String() {
if provisionerDaemon.ID != id {
continue
}
return provisionerDaemon, nil
Expand All @@ -1711,7 +1711,7 @@ func (q *fakeQuerier) GetWorkspaceResourceByID(_ context.Context, id uuid.UUID)
defer q.mutex.RUnlock()

for _, resource := range q.provisionerJobResources {
if resource.ID.String() == id.String() {
if resource.ID == id {
return resource, nil
}
}
Expand All @@ -1724,7 +1724,7 @@ func (q *fakeQuerier) GetWorkspaceResourcesByJobID(_ context.Context, jobID uuid

resources := make([]database.WorkspaceResource, 0)
for _, resource := range q.provisionerJobResources {
if resource.JobID.String() != jobID.String() {
if resource.JobID != jobID {
continue
}
resources = append(resources, resource)
Expand Down Expand Up @@ -1791,7 +1791,7 @@ func (q *fakeQuerier) GetWorkspaceResourceMetadataByResourceID(_ context.Context

metadata := make([]database.WorkspaceResourceMetadatum, 0)
for _, metadatum := range q.provisionerJobResourceMetadata {
if metadatum.WorkspaceResourceID.String() == id.String() {
if metadatum.WorkspaceResourceID == id {
metadata = append(metadata, metadatum)
}
}
Expand All @@ -1805,7 +1805,7 @@ func (q *fakeQuerier) GetWorkspaceResourceMetadataByResourceIDs(_ context.Contex
metadata := make([]database.WorkspaceResourceMetadatum, 0)
for _, metadatum := range q.provisionerJobResourceMetadata {
for _, id := range ids {
if metadatum.WorkspaceResourceID.String() == id.String() {
if metadatum.WorkspaceResourceID == id {
metadata = append(metadata, metadatum)
}
}
Expand All @@ -1820,7 +1820,7 @@ func (q *fakeQuerier) GetProvisionerJobsByIDs(_ context.Context, ids []uuid.UUID
jobs := make([]database.ProvisionerJob, 0)
for _, job := range q.provisionerJobs {
for _, id := range ids {
if id.String() == job.ID.String() {
if id == job.ID {
jobs = append(jobs, job)
break
}
Expand Down Expand Up @@ -1852,7 +1852,7 @@ func (q *fakeQuerier) GetProvisionerLogsByIDBetween(_ context.Context, arg datab

logs := make([]database.ProvisionerJobLog, 0)
for _, jobLog := range q.provisionerJobLogs {
if jobLog.JobID.String() != arg.JobID.String() {
if jobLog.JobID != arg.JobID {
continue
}
if !arg.CreatedBefore.IsZero() && jobLog.CreatedAt.After(arg.CreatedBefore) {
Expand Down Expand Up @@ -2663,7 +2663,7 @@ func (q *fakeQuerier) UpdateGitSSHKey(_ context.Context, arg database.UpdateGitS
defer q.mutex.Unlock()

for index, key := range q.gitSSHKey {
if key.UserID.String() != arg.UserID.String() {
if key.UserID != arg.UserID {
continue
}
key.UpdatedAt = arg.UpdatedAt
Expand Down Expand Up @@ -2726,7 +2726,7 @@ func (q *fakeQuerier) DeleteGitSSHKey(_ context.Context, userID uuid.UUID) error
defer q.mutex.Unlock()

for index, key := range q.gitSSHKey {
if key.UserID.String() != userID.String() {
if key.UserID != userID {
continue
}
q.gitSSHKey[index] = q.gitSSHKey[len(q.gitSSHKey)-1]
Expand Down Expand Up @@ -3039,7 +3039,7 @@ func (q *fakeQuerier) InsertGroup(_ context.Context, arg database.InsertGroupPar
defer q.mutex.RUnlock()

for _, group := range q.groups {
if group.OrganizationID.String() == arg.OrganizationID.String() &&
if group.OrganizationID == arg.OrganizationID &&
group.Name == arg.Name {
return database.Group{}, errDuplicateKey
}
Expand Down