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

Commit45f8bc6

Browse files
keep older version
1 parent03f1345 commit45f8bc6

File tree

1 file changed

+91
-1
lines changed

1 file changed

+91
-1
lines changed

‎coderd/database/dbmem/dbmem.go

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,96 @@ func (q *FakeQuerier) getProvisionerJobsByIDsWithQueuePositionLocked(_ context.C
12591259
returnresults,nil
12601260
}
12611261

1262+
func (q*FakeQuerier)getProvisionerJobsByIDsWithQueuePositionLockedV0(_ context.Context,ids []uuid.UUID) ([]database.GetProvisionerJobsByIDsWithQueuePositionRow,error) {
1263+
//WITH pending_jobs AS (
1264+
//SELECT
1265+
//id, created_at
1266+
//FROM
1267+
//provisioner_jobs
1268+
//WHERE
1269+
//started_at IS NULL
1270+
//AND
1271+
//canceled_at IS NULL
1272+
//AND
1273+
//completed_at IS NULL
1274+
//AND
1275+
//error IS NULL
1276+
//),
1277+
typependingJobRowstruct {
1278+
ID uuid.UUID
1279+
CreatedAt time.Time
1280+
}
1281+
pendingJobs:=make([]pendingJobRow,0)
1282+
for_,job:=rangeq.provisionerJobs {
1283+
ifjob.StartedAt.Valid||
1284+
job.CanceledAt.Valid||
1285+
job.CompletedAt.Valid||
1286+
job.Error.Valid {
1287+
continue
1288+
}
1289+
pendingJobs=append(pendingJobs,pendingJobRow{
1290+
ID:job.ID,
1291+
CreatedAt:job.CreatedAt,
1292+
})
1293+
}
1294+
1295+
//queue_position AS (
1296+
//SELECT
1297+
//id,
1298+
//ROW_NUMBER() OVER (ORDER BY created_at ASC) AS queue_position
1299+
//FROM
1300+
//pending_jobs
1301+
// ),
1302+
slices.SortFunc(pendingJobs,func(a,bpendingJobRow)int {
1303+
c:=a.CreatedAt.Compare(b.CreatedAt)
1304+
returnc
1305+
})
1306+
1307+
queuePosition:=make(map[uuid.UUID]int64)
1308+
foridx,pj:=rangependingJobs {
1309+
queuePosition[pj.ID]=int64(idx+1)
1310+
}
1311+
1312+
//queue_size AS (
1313+
//SELECT COUNT(*) AS count FROM pending_jobs
1314+
//),
1315+
queueSize:=len(pendingJobs)
1316+
1317+
//SELECT
1318+
//sqlc.embed(pj),
1319+
//COALESCE(qp.queue_position, 0) AS queue_position,
1320+
//COALESCE(qs.count, 0) AS queue_size
1321+
// FROM
1322+
//provisioner_jobs pj
1323+
//LEFT JOIN
1324+
//queue_position qp ON pj.id = qp.id
1325+
//LEFT JOIN
1326+
//queue_size qs ON TRUE
1327+
//WHERE
1328+
//pj.id IN (...)
1329+
jobs:=make([]database.GetProvisionerJobsByIDsWithQueuePositionRow,0)
1330+
for_,job:=rangeq.provisionerJobs {
1331+
ifids!=nil&&!slices.Contains(ids,job.ID) {
1332+
continue
1333+
}
1334+
// clone the Tags before appending, since maps are reference types and
1335+
// we don't want the caller to be able to mutate the map we have inside
1336+
// dbmem!
1337+
job.Tags=maps.Clone(job.Tags)
1338+
job:= database.GetProvisionerJobsByIDsWithQueuePositionRow{
1339+
//sqlc.embed(pj),
1340+
ProvisionerJob:job,
1341+
//COALESCE(qp.queue_position, 0) AS queue_position,
1342+
QueuePosition:queuePosition[job.ID],
1343+
//COALESCE(qs.count, 0) AS queue_size
1344+
QueueSize:int64(queueSize),
1345+
}
1346+
jobs=append(jobs,job)
1347+
}
1348+
1349+
returnjobs,nil
1350+
}
1351+
12621352
func (*FakeQuerier)AcquireLock(_ context.Context,_int64)error {
12631353
returnxerrors.New("AcquireLock must only be called within a transaction")
12641354
}
@@ -4240,7 +4330,7 @@ func (q *FakeQuerier) GetProvisionerJobsByOrganizationAndStatusWithQueuePosition
42404330
LIMIT
42414331
sqlc.narg('limit')::int;
42424332
*/
4243-
rowsWithQueuePosition,err:=q.getProvisionerJobsByIDsWithQueuePositionLocked(ctx,nil)
4333+
rowsWithQueuePosition,err:=q.getProvisionerJobsByIDsWithQueuePositionLockedV0(ctx,nil)
42444334
iferr!=nil {
42454335
returnnil,err
42464336
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp