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

Commit2cf4b5c

Browse files
authored
perf: optimize prebuilds membership reconciliation to check orgs not presets (#20493) (#20555)
Related to PR:#20493(cherry picked from commit7e8fcb4)
1 parenta7b3efb commit2cf4b5c

File tree

10 files changed

+397
-212
lines changed

10 files changed

+397
-212
lines changed

‎coderd/database/dbauthz/dbauthz.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,6 +2649,13 @@ func (q *querier) GetOrganizationsByUserID(ctx context.Context, userID database.
26492649
returnfetchWithPostFilter(q.auth,policy.ActionRead,q.db.GetOrganizationsByUserID)(ctx,userID)
26502650
}
26512651

2652+
func (q*querier)GetOrganizationsWithPrebuildStatus(ctx context.Context,arg database.GetOrganizationsWithPrebuildStatusParams) ([]database.GetOrganizationsWithPrebuildStatusRow,error) {
2653+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceOrganization.All());err!=nil {
2654+
returnnil,err
2655+
}
2656+
returnq.db.GetOrganizationsWithPrebuildStatus(ctx,arg)
2657+
}
2658+
26522659
func (q*querier)GetParameterSchemasByJobID(ctx context.Context,jobID uuid.UUID) ([]database.ParameterSchema,error) {
26532660
version,err:=q.db.GetTemplateVersionByJobID(ctx,jobID)
26542661
iferr!=nil {

‎coderd/database/dbauthz/dbauthz_test.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3759,6 +3759,14 @@ func (s *MethodTestSuite) TestPrebuilds() {
37593759
dbm.EXPECT().GetPrebuildMetrics(gomock.Any()).Return([]database.GetPrebuildMetricsRow{},nil).AnyTimes()
37603760
check.Args().Asserts(rbac.ResourceWorkspace.All(),policy.ActionRead)
37613761
}))
3762+
s.Run("GetOrganizationsWithPrebuildStatus",s.Mocked(func(dbm*dbmock.MockStore,faker*gofakeit.Faker,check*expects) {
3763+
arg:= database.GetOrganizationsWithPrebuildStatusParams{
3764+
UserID:uuid.New(),
3765+
GroupName:"test",
3766+
}
3767+
dbm.EXPECT().GetOrganizationsWithPrebuildStatus(gomock.Any(),arg).Return([]database.GetOrganizationsWithPrebuildStatusRow{},nil).AnyTimes()
3768+
check.Args(arg).Asserts(rbac.ResourceOrganization.All(),policy.ActionRead)
3769+
}))
37623770
s.Run("GetPrebuildsSettings",s.Mocked(func(dbm*dbmock.MockStore,_*gofakeit.Faker,check*expects) {
37633771
dbm.EXPECT().GetPrebuildsSettings(gomock.Any()).Return("{}",nil).AnyTimes()
37643772
check.Args().Asserts()

‎coderd/database/dbmetrics/querymetrics.go‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbmock/dbmock.go‎

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier.go‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go‎

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/prebuilds.sql‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,47 @@ SET
327327
FROM jobs_to_cancel
328328
WHEREprovisioner_jobs.id=jobs_to_cancel.id
329329
RETURNINGjobs_to_cancel.id,jobs_to_cancel.workspace_id,jobs_to_cancel.template_id,jobs_to_cancel.template_version_preset_id;
330+
331+
-- name: GetOrganizationsWithPrebuildStatus :many
332+
-- GetOrganizationsWithPrebuildStatus returns organizations with prebuilds configured and their
333+
-- membership status for the prebuilds system user (org membership, group existence, group membership).
334+
WITH orgs_with_prebuildsAS (
335+
-- Get unique organizations that have presets with prebuilds configured
336+
SELECT DISTINCTo.id,o.name
337+
FROM organizations o
338+
INNER JOIN templates tONt.organization_id=o.id
339+
INNER JOIN template_versions tvONtv.template_id=t.id
340+
INNER JOIN template_version_presets tvpONtvp.template_version_id=tv.id
341+
WHEREtvp.desired_instancesIS NOT NULL
342+
),
343+
prebuild_user_membershipAS (
344+
-- Check if the user is a member of the organizations
345+
SELECTom.organization_id
346+
FROM organization_members om
347+
INNER JOIN orgs_with_prebuilds owpONowp.id=om.organization_id
348+
WHEREom.user_id= @user_id::uuid
349+
),
350+
prebuild_groupsAS (
351+
-- Check if the organizations have the prebuilds group
352+
SELECTg.organization_id,g.idas group_id
353+
FROM groups g
354+
INNER JOIN orgs_with_prebuilds owpONowp.id=g.organization_id
355+
WHEREg.name= @group_name::text
356+
),
357+
prebuild_group_membershipAS (
358+
-- Check if the user is in the prebuilds group
359+
SELECTpg.organization_id
360+
FROM prebuild_groups pg
361+
INNER JOIN group_members gmONgm.group_id=pg.group_id
362+
WHEREgm.user_id= @user_id::uuid
363+
)
364+
SELECT
365+
owp.idAS organization_id,
366+
owp.nameAS organization_name,
367+
(pum.organization_idIS NOT NULL)::booleanAS has_prebuild_user,
368+
pg.group_idAS prebuilds_group_id,
369+
(pgm.organization_idIS NOT NULL)::booleanAS has_prebuild_user_in_group
370+
FROM orgs_with_prebuilds owp
371+
LEFT JOIN prebuild_groups pgONpg.organization_id=owp.id
372+
LEFT JOIN prebuild_user_membership pumONpum.organization_id=owp.id
373+
LEFT JOIN prebuild_group_membership pgmONpgm.organization_id=owp.id;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp