Skip to content

Commit 08412fd

Browse files
authored
chore: Remove unused SQL functions (#5857)
* chore: Remove unused sql functions - GetProvisionerDaemonByID - UpdateProvisionerDaemonByID - GetUserGroups - GetWorkspaceCountByUserID - GetLatestAgentStat
1 parent b678309 commit 08412fd

File tree

7 files changed

+2
-253
lines changed

7 files changed

+2
-253
lines changed

coderd/database/databasefake/databasefake.go

-80
Original file line numberDiff line numberDiff line change
@@ -283,33 +283,6 @@ func (q *fakeQuerier) InsertAgentStat(_ context.Context, p database.InsertAgentS
283283
return stat, nil
284284
}
285285

286-
func (q *fakeQuerier) GetLatestAgentStat(_ context.Context, agentID uuid.UUID) (database.AgentStat, error) {
287-
q.mutex.RLock()
288-
defer q.mutex.RUnlock()
289-
290-
found := false
291-
latest := database.AgentStat{}
292-
for _, agentStat := range q.agentStats {
293-
if agentStat.AgentID != agentID {
294-
continue
295-
}
296-
if !found {
297-
latest = agentStat
298-
found = true
299-
continue
300-
}
301-
if agentStat.CreatedAt.After(latest.CreatedAt) {
302-
latest = agentStat
303-
found = true
304-
continue
305-
}
306-
}
307-
if !found {
308-
return database.AgentStat{}, sql.ErrNoRows
309-
}
310-
return latest, nil
311-
}
312-
313286
func (q *fakeQuerier) GetTemplateDAUs(_ context.Context, templateID uuid.UUID) ([]database.GetTemplateDAUsRow, error) {
314287
q.mutex.Lock()
315288
defer q.mutex.Unlock()
@@ -1305,22 +1278,6 @@ func (q *fakeQuerier) GetWorkspaceBuildByID(_ context.Context, id uuid.UUID) (da
13051278
return database.WorkspaceBuild{}, sql.ErrNoRows
13061279
}
13071280

1308-
func (q *fakeQuerier) GetWorkspaceCountByUserID(_ context.Context, id uuid.UUID) (int64, error) {
1309-
q.mutex.RLock()
1310-
defer q.mutex.RUnlock()
1311-
var count int64
1312-
for _, workspace := range q.workspaces {
1313-
if workspace.OwnerID == id {
1314-
if workspace.Deleted {
1315-
continue
1316-
}
1317-
1318-
count++
1319-
}
1320-
}
1321-
return count, nil
1322-
}
1323-
13241281
func (q *fakeQuerier) GetWorkspaceBuildByJobID(_ context.Context, jobID uuid.UUID) (database.WorkspaceBuild, error) {
13251282
q.mutex.RLock()
13261283
defer q.mutex.RUnlock()
@@ -2289,19 +2246,6 @@ func (q *fakeQuerier) GetWorkspaceAppByAgentIDAndSlug(_ context.Context, arg dat
22892246
return database.WorkspaceApp{}, sql.ErrNoRows
22902247
}
22912248

2292-
func (q *fakeQuerier) GetProvisionerDaemonByID(_ context.Context, id uuid.UUID) (database.ProvisionerDaemon, error) {
2293-
q.mutex.RLock()
2294-
defer q.mutex.RUnlock()
2295-
2296-
for _, provisionerDaemon := range q.provisionerDaemons {
2297-
if provisionerDaemon.ID != id {
2298-
continue
2299-
}
2300-
return provisionerDaemon, nil
2301-
}
2302-
return database.ProvisionerDaemon{}, sql.ErrNoRows
2303-
}
2304-
23052249
func (q *fakeQuerier) GetProvisionerJobByID(_ context.Context, id uuid.UUID) (database.ProvisionerJob, error) {
23062250
q.mutex.RLock()
23072251
defer q.mutex.RUnlock()
@@ -3238,26 +3182,6 @@ func (q *fakeQuerier) UpdateTemplateVersionDescriptionByJobID(_ context.Context,
32383182
return sql.ErrNoRows
32393183
}
32403184

3241-
func (q *fakeQuerier) UpdateProvisionerDaemonByID(_ context.Context, arg database.UpdateProvisionerDaemonByIDParams) error {
3242-
if err := validateDatabaseType(arg); err != nil {
3243-
return err
3244-
}
3245-
3246-
q.mutex.Lock()
3247-
defer q.mutex.Unlock()
3248-
3249-
for index, daemon := range q.provisionerDaemons {
3250-
if arg.ID != daemon.ID {
3251-
continue
3252-
}
3253-
daemon.UpdatedAt = arg.UpdatedAt
3254-
daemon.Provisioners = arg.Provisioners
3255-
q.provisionerDaemons[index] = daemon
3256-
return nil
3257-
}
3258-
return sql.ErrNoRows
3259-
}
3260-
32613185
func (q *fakeQuerier) UpdateWorkspaceAgentConnectionByID(_ context.Context, arg database.UpdateWorkspaceAgentConnectionByIDParams) error {
32623186
if err := validateDatabaseType(arg); err != nil {
32633187
return err
@@ -4046,10 +3970,6 @@ func (q *fakeQuerier) InsertGroup(_ context.Context, arg database.InsertGroupPar
40463970
return group, nil
40473971
}
40483972

4049-
func (*fakeQuerier) GetUserGroups(_ context.Context, _ uuid.UUID) ([]database.Group, error) {
4050-
panic("not implemented")
4051-
}
4052-
40533973
func (q *fakeQuerier) GetGroupMembers(_ context.Context, groupID uuid.UUID) ([]database.User, error) {
40543974
q.mutex.RLock()
40553975
defer q.mutex.RUnlock()

coderd/database/querier.go

-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+1-125
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/agentstats.sql

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ INSERT INTO
1212
VALUES
1313
($1, $2, $3, $4, $5, $6, $7) RETURNING *;
1414

15-
-- name: GetLatestAgentStat :one
16-
SELECT * FROM agent_stats WHERE agent_id = $1 ORDER BY created_at DESC LIMIT 1;
17-
1815
-- name: GetTemplateDAUs :many
19-
SELECT
16+
SELECT
2017
(created_at at TIME ZONE 'UTC')::date as date,
2118
user_id
2219
FROM

coderd/database/queries/groups.sql

-12
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ AND
2020
LIMIT
2121
1;
2222

23-
-- name: GetUserGroups :many
24-
SELECT
25-
groups.*
26-
FROM
27-
groups
28-
JOIN
29-
group_members
30-
ON
31-
groups.id = group_members.group_id
32-
WHERE
33-
group_members.user_id = $1;
34-
3523
-- name: GetGroupMembers :many
3624
SELECT
3725
users.*
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
-- name: GetProvisionerDaemonByID :one
2-
SELECT
3-
*
4-
FROM
5-
provisioner_daemons
6-
WHERE
7-
id = $1;
8-
91
-- name: GetProvisionerDaemons :many
102
SELECT
113
*
@@ -23,12 +15,3 @@ INSERT INTO
2315
)
2416
VALUES
2517
($1, $2, $3, $4, $5) RETURNING *;
26-
27-
-- name: UpdateProvisionerDaemonByID :exec
28-
UPDATE
29-
provisioner_daemons
30-
SET
31-
updated_at = $2,
32-
provisioners = $3
33-
WHERE
34-
id = $1;

coderd/database/queries/workspaces.sql

-10
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,6 @@ WHERE
236236
GROUP BY
237237
template_id;
238238

239-
-- name: GetWorkspaceCountByUserID :one
240-
SELECT
241-
COUNT(id)
242-
FROM
243-
workspaces
244-
WHERE
245-
owner_id = @owner_id
246-
-- Ignore deleted workspaces
247-
AND deleted != true;
248-
249239
-- name: InsertWorkspace :one
250240
INSERT INTO
251241
workspaces (

0 commit comments

Comments
 (0)