Skip to content

refactor(coderd): collapse activityBumpWorkspace into a single query#9652

Merged
johnstcn merged 18 commits into
mainfrom
cj/activitybump_query
Sep 14, 2023
Merged

refactor(coderd): collapse activityBumpWorkspace into a single query#9652
johnstcn merged 18 commits into
mainfrom
cj/activitybump_query

Conversation

@johnstcn

@johnstcn johnstcn commented Sep 12, 2023

Copy link
Copy Markdown
Member

Fixes #8064

Explain output for updated query (ran on big.cdr.dev): https://explain.dalibo.com/plan/365gcg47eh1dc171

@johnstcn johnstcn self-assigned this Sep 12, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-review: I can inline this CTE if required, but I think the readability is important here. I'm preserving the comments from the original pure-Go implementation for reference.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-review: I view these tests as complementary to TestWorkspaceActivityBump in activitybump_test.go; testing the end-to-end functionality here is crucial.

workspace_builds.max_deadline::timestamp AS build_max_deadline,
workspace_builds.transition AS build_transition,
provisioner_jobs.completed_at::timestamp AS job_completed_at,
(workspaces.ttl / 1000 / 1000 / 1000 || ' seconds')::interval AS ttl_interval,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-review: it probably makes sense to migrate this column to e.g. ttl_mins, but that's out of scope of this PR.

@johnstcn johnstcn marked this pull request as ready for review September 13, 2023 15:08
Comment thread coderd/database/queries/activitybump.sql Outdated
Comment thread coderd/database/queries/activitybump.sql Outdated
@johnstcn

Copy link
Copy Markdown
Member Author

Poll: should I make this an experiment?

@mafredri

Copy link
Copy Markdown
Member

Poll: should I make this an experiment?

If I understood correctly, logic changes here. So I guess it depends on if this is a bugfix or improvement. If it's the latter this could be an experiment or breaking change. If it's the former I guess still breaking but no need to put it behind experiment.

@johnstcn

johnstcn commented Sep 13, 2023

Copy link
Copy Markdown
Member Author

Poll: should I make this an experiment?

If I understood correctly, logic changes here. So I guess it depends on if this is a bugfix or improvement. If it's the latter this could be an experiment or breaking change. If it's the former I guess still breaking but no need to put it behind experiment.

It's a refactor, so there should be absolutely no functional changes. I made sure that the tests I added covered the existing logic before modifying the logic. So there should be absolutely no difference.

Comment thread coderd/database/dbfake/dbfake.go
@Emyrk

Emyrk commented Sep 13, 2023

Copy link
Copy Markdown
Member

I would say not to make it an experiment. It should have the same behavior

@johnstcn johnstcn requested a review from mafredri September 13, 2023 16:13
SET
updated_at = NOW(),
deadline = CASE
WHEN l.build_max_deadline = '0001-01-01 00:00:00'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, maybe, this actually should be in +00 format (UTC), but it depends on what our default value is and DB being in non-UTC config. I imagine this is something we may be doing (potentially) incorrectly elsewhere too so maybe doesn't need fixing in this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, max deadline is +00. I'll update that to fix, but good catch.

@mtojek mtojek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO there is no need to put it under experiment. If there is a problem with the routine, you can easily revert the change 👍

LGTM, I see that major comments have been addressed.

return ks, nil
}

func minTime(t, u time.Time) time.Time {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if this is used only by ActivityBumpWorkspace, then I would move it below/to the bottom.

@johnstcn johnstcn merged commit 8b6e286 into main Sep 14, 2023
@johnstcn johnstcn deleted the cj/activitybump_query branch September 14, 2023 08:09
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create dedicated query for bumping workspace activity

4 participants