Skip to content

Commit

Permalink
Fix query
Browse files Browse the repository at this point in the history
  • Loading branch information
Redm4x committed Feb 22, 2024
1 parent 97b6dcd commit c437f60
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions api/src/routers/internalRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,18 @@ internalRouter.get("/gpu", async (c) => {

const gpuNodes = (await chainDb.query(
`
WITH nodes_with_gpu AS (
WITH snapshots AS (
SELECT DISTINCT ON("hostUri")
"hostUri",
p."owner",
psn.id AS "id",
name,
"gpuAllocatable" AS "allocatable",
"gpuAllocated" AS "allocated"
ps.id AS id,
"hostUri",
p."owner"
FROM provider p
INNER JOIN "providerSnapshot" ps ON ps.id=p."lastSnapshotId"
INNER JOIN "providerSnapshotNode" psn ON psn."snapshotId"=ps.id
WHERE p."isOnline" IS TRUE AND "gpuAllocatable" > 0
WHERE p."isOnline" IS TRUE
)
SELECT n."hostUri", n."name", n."allocatable", n."allocated", gpu."modelId", gpu.vendor, gpu.name AS "modelName", gpu.interface, gpu."memorySize"
FROM nodes_with_gpu n
SELECT s."hostUri", n."name", n."gpuAllocatable" AS allocatable, n."gpuAllocated" AS allocated, gpu."modelId", gpu.vendor, gpu.name AS "modelName", gpu.interface, gpu."memorySize"
FROM snapshots s
INNER JOIN "providerSnapshotNode" n ON n."snapshotId"=s.id AND n."gpuAllocatable" > 0
LEFT JOIN (
SELECT DISTINCT ON (gpu."snapshotNodeId") gpu.*
FROM "providerSnapshotNodeGPU" gpu
Expand All @@ -96,8 +93,8 @@ internalRouter.get("/gpu", async (c) => {
(:vendor IS NULL OR gpu.vendor = :vendor)
AND (:model IS NULL OR gpu.name = :model)
AND (:memory_size IS NULL OR gpu."memorySize" = :memory_size)
AND (:provider_address IS NULL OR n."owner" = :provider_address)
AND (:provider_hosturi IS NULL OR n."hostUri" = :provider_hosturi)
AND (:provider_address IS NULL OR s."owner" = :provider_address)
AND (:provider_hosturi IS NULL OR s."hostUri" = :provider_hosturi)
`,
{
type: QueryTypes.SELECT,
Expand Down

0 comments on commit c437f60

Please sign in to comment.