From ef12168811baa5bbc245c236f381fc3deff62b00 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sun, 3 Oct 2021 21:22:00 +0200 Subject: [PATCH] Make it possible to list one specific sequence --- lib/www/server/lib/db/sequence/list.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/www/server/lib/db/sequence/list.js b/lib/www/server/lib/db/sequence/list.js index afc1081..a468db2 100644 --- a/lib/www/server/lib/db/sequence/list.js +++ b/lib/www/server/lib/db/sequence/list.js @@ -14,8 +14,12 @@ async function list (projectId, opts = {}) { const filter = opts.filter; const noFilter = !("filter" in opts) || opts.filter === null || !String(opts.filter).trim().length; + const sequenceText = opts.sequence + ? "sequence = $4" + : "$4 = $4"; + const filterText = noFilter - ? "TRUE" + ? "$3 = $3" : ` $3 = sequence::text OR line::text ~ $3 @@ -26,7 +30,7 @@ async function list (projectId, opts = {}) { OR (($3 ILIKE 'process%' OR $3 ILIKE 'final%') AND duration_final IS NOT NULL) OR ($3 ILIKE 'raw' AND duration_final IS NULL) `; - + const missing_shots = opts.missing ? `, COALESCE((SELECT jsonb_agg(msrp) FROM missing_sequence_raw_points msrp WHERE msrp.sequence = ss.sequence), '[]'::jsonb) missing_raw, @@ -62,14 +66,14 @@ async function list (projectId, opts = {}) { `) + ` WHERE + ${sequenceText} AND ${filterText} ORDER BY ${sortKey} ${sortDir} OFFSET $1 LIMIT $2; `; - const values = [offset, limit]; - if (!noFilter) values.push(filter); + const values = [offset, limit, filter||0, opts.sequence||0]; const res = await client.query(text, values); client.release(); return res.rows;