Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: initiator_username joined to workspace_build queries#2137

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Emyrk wants to merge4 commits intomainfromstevenmasley/build_initiator_username

Conversation

@Emyrk
Copy link
Member

@EmyrkEmyrk commentedJun 7, 2022
edited
Loading

What this does

Allworkspace_builds now also returninitiator_name withinitiator_id. This allows the UI to use the username of the initiator.

UsesPG views to make models for sqlc.

Future Work

Currently autostart related entries use the workspace owner as the initator. We should change this to show some "autostart" or "system" user.

InitiatorID:workspace.OwnerID,

@EmyrkEmyrk marked this pull request as ready for reviewJune 7, 2022 20:56
@EmyrkEmyrk requested a review froma team as acode ownerJune 7, 2022 20:56
Comment on lines +1 to +7
-- This view adds the initiator name to the query for UI purposes.
-- Showing the initiator user ID is not very friendly.
CREATE VIEW workspace_build_with_initiator AS
-- If the user is nil, just use 'unknown' for now.
SELECT workspace_builds.*, coalesce(users.username, 'unknown') AS initiator_username
FROM workspace_builds
LEFT JOIN users ON workspace_builds.initiator_id = users.id;
Copy link
Member

Choose a reason for hiding this comment

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

Will this require adding a migration every time we want to change the query?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@kylecarbs yes. Another migration will drop the old view and make a new one.

If we change the columns, it will be required too as thedump.sql expands*. I just realized that 🤔

Copy link
MemberAuthor

@EmyrkEmyrkJun 8, 2022
edited
Loading

Choose a reason for hiding this comment

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

Unless we implement something else to "migrate" views.

A view is a saved query on the database. The alternative is to use temporary views which only last for a single "session".So this alternative thing to "migrate" views could be a set of temporary views we initiate when we open a SQL connection. (maybe, brainstorming here, I think that would work) With connection pooling this might not work.

Copy link
Member

@Kira-PilotKira-Pilot left a comment

Choose a reason for hiding this comment

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

FE ✔️

Copy link
Member

@kylecarbskylecarbs left a comment

Choose a reason for hiding this comment

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

Because this introduces a new paradigm, I'm a lot more hesitant. Adjusting the schema of workspace builds would now have a dependency on updating thisVIEW too.

Because we already query theowner, could we add the initiator to that query instead? Then it'd be the same number of queries, but just an additional row returned. We already haveGetUsersByIDs, so it should be relatively straightforward to swap out.

AJOIN will certainly be more performant, but I'm mostly concerned about the complexity of interfacing with our database at this point, much less the performance overhead of fetching a lil more data.

I'd love to understand your thoughts here@Emyrk, it's very possible I'm misunderstanding how this should be used.

@Emyrk
Copy link
MemberAuthor

Emyrk commentedJun 8, 2022
edited
Loading

Just had a conversation with@kylecarbs in discord.

In summary, the views are a method that enables using joins in our SQL queries, which is powerful and can cut down on the number of DB calls we make.

The contention to pushing this PR through is maintaining the view, and defaulting to using joins.

Con: Maintaining the view

This PR adds a view ontop ofworkspace_builds calledworkspace_build_with_initiator. If a column is added toworkspace_build, that column isnot automatically added to the view. So your migration will look like this:

-- We must drop the old view first, then recreate it. We cannot just update the old view-- as the new view must have the same columns.DROPVIEW workspace_build_with_initiator;-- This alter table could be adding a column OR removing a column. In both cases, we will-- need to drop the view first.-- You cannot delete a column that has a dependency on it, and a view is a dependency.ALTERTABLE workspace_builds    ADD extra_columnint DEFAULT1NOT NULL;CREATEVIEWworkspace_build_with_initiatorASSELECT workspace_builds.*, coalesce(users.username,'unknown')AS initiator_usernameFROM workspace_buildsLEFT JOIN usersONworkspace_builds.initiator_id=users.id;

The biggest downside is that is adds some complexity to our migrations. The developer writing the migration needs to know which views to also update. They will likely have to copy theCREATE VIEW ... code block from migration to migration.

This is just the cost of the views.

Con: Defaulting to using joins

One downside is that all our queries now use joins. In the example above, the data being joined is only used by the UI. So internal usage doesn't require the join (at the moment). However, having the additional context could be nice for logging purposes, so it might not be a total waste.

I don't think join performance will be so bad that this is really an issue, but it can cause over-fetching.

The upside

  • Less db calls as we can merge them into 1 with a join
  • Still 1database.Type shared by all sqlc queries
  • Join queries are reused, and only typed once.

Alternative (Status Quo)

The alternative is to do the status quo, where we make multiple db calls and merge the resulting structs.

  • Query for workspace build
  • Query for owner & initiator user's
  • Merge in a goconvertWorkspaceBuild function.
    • Handling errors in convert is currently inconsistent. The SQL joins handle these more consistently.

Extra links

SQLc implementations that could help. But gated since these features do not exist yet :(.

@Emyrk
Copy link
MemberAuthor

Emyrk commentedJun 8, 2022
edited
Loading

I am going to close this PR in favor of the status quofor now. I will work on this PR to include some other views that could benefit and get a larger team decision about this.

This is a repo design and maintenance change, so will be a discussion. Until then, we still need the feature, so I'll do it in another PR

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@kylecarbskylecarbskylecarbs left review comments

@Kira-PilotKira-PilotKira-Pilot approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@Emyrk@kylecarbs@Kira-Pilot

[8]ページ先頭

©2009-2025 Movatter.jp