mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix: use unique workspace owners over unique users (#11044)
This commit is contained in:
@ -4520,6 +4520,36 @@ func (q *FakeQuerier) GetWorkspaceResourcesCreatedAfter(_ context.Context, after
|
||||
return resources, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetWorkspaceUniqueOwnerCountByTemplateIDs(_ context.Context, templateIds []uuid.UUID) ([]database.GetWorkspaceUniqueOwnerCountByTemplateIDsRow, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
workspaceOwners := make(map[uuid.UUID]map[uuid.UUID]struct{})
|
||||
for _, workspace := range q.workspaces {
|
||||
if workspace.Deleted {
|
||||
continue
|
||||
}
|
||||
if !slices.Contains(templateIds, workspace.TemplateID) {
|
||||
continue
|
||||
}
|
||||
_, ok := workspaceOwners[workspace.TemplateID]
|
||||
if !ok {
|
||||
workspaceOwners[workspace.TemplateID] = make(map[uuid.UUID]struct{})
|
||||
}
|
||||
workspaceOwners[workspace.TemplateID][workspace.OwnerID] = struct{}{}
|
||||
}
|
||||
resp := make([]database.GetWorkspaceUniqueOwnerCountByTemplateIDsRow, 0)
|
||||
for _, templateID := range templateIds {
|
||||
count := len(workspaceOwners[templateID])
|
||||
resp = append(resp, database.GetWorkspaceUniqueOwnerCountByTemplateIDsRow{
|
||||
TemplateID: templateID,
|
||||
UniqueOwnersSum: int64(count),
|
||||
})
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetWorkspaces(ctx context.Context, arg database.GetWorkspacesParams) ([]database.GetWorkspacesRow, error) {
|
||||
if err := validateDatabaseType(arg); err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user