Skip to content

fix: make GetWorkspacesEligibleForTransition return less false-positives #15429

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 7 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
revert: cache
  • Loading branch information
DanielleMaywood committed Nov 7, 2024
commit e81a985a94abee23ae2d5776148536b18d88126c
41 changes: 0 additions & 41 deletions coderd/autobuild/cache.go

This file was deleted.

84 changes: 0 additions & 84 deletions coderd/autobuild/cache_test.go

This file was deleted.

26 changes: 4 additions & 22 deletions coderd/autobuild/lifecycle_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,6 @@ func (e *Executor) runOnce(t time.Time) Stats {
// Limit the concurrency to avoid overloading the database.
eg.SetLimit(10)

// We cache these values to help reduce load on the database.
// These could be outdated during our execution, but this is
// unlikely to be noticed or cause any unwanted behaviour.
var (
userCache = newCacheOf[uuid.UUID, database.User]()
templateCache = newCacheOf[uuid.UUID, database.Template]()
templateVersionCache = newCacheOf[uuid.UUID, database.TemplateVersion]()
templateScheduleCache = newCacheOf[uuid.UUID, schedule.TemplateScheduleOptions]()
)

for _, ws := range workspaces {
wsID := ws.ID
wsName := ws.Name
Expand Down Expand Up @@ -194,9 +184,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
return xerrors.Errorf("get workspace by id: %w", err)
}

user, err := userCache.LoadOrStore(ws.OwnerID, func() (database.User, error) {
return tx.GetUserByID(e.ctx, ws.OwnerID)
})
user, err := tx.GetUserByID(e.ctx, ws.OwnerID)
if err != nil {
return xerrors.Errorf("get user by id: %w", err)
}
Expand All @@ -212,23 +200,17 @@ func (e *Executor) runOnce(t time.Time) Stats {
return xerrors.Errorf("get latest provisioner job: %w", err)
}

templateSchedule, err := templateScheduleCache.LoadOrStore(ws.TemplateID, func() (schedule.TemplateScheduleOptions, error) {
return (*(e.templateScheduleStore.Load())).Get(e.ctx, tx, ws.TemplateID)
})
templateSchedule, err := (*(e.templateScheduleStore.Load())).Get(e.ctx, tx, ws.TemplateID)
if err != nil {
return xerrors.Errorf("get template scheduling options: %w", err)
}

tmpl, err := templateCache.LoadOrStore(ws.TemplateID, func() (database.Template, error) {
return tx.GetTemplateByID(e.ctx, ws.TemplateID)
})
tmpl, err := tx.GetTemplateByID(e.ctx, ws.TemplateID)
if err != nil {
return xerrors.Errorf("get template by ID: %w", err)
}

activeTemplateVersion, err = templateVersionCache.LoadOrStore(tmpl.ActiveVersionID, func() (database.TemplateVersion, error) {
return tx.GetTemplateVersionByID(e.ctx, tmpl.ActiveVersionID)
})
activeTemplateVersion, err = tx.GetTemplateVersionByID(e.ctx, tmpl.ActiveVersionID)
if err != nil {
return xerrors.Errorf("get active template version by ID: %w", err)
}
Expand Down