From d3d535a8beafd599c2630d984c663cde1c4e6a0f Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sun, 4 Oct 2020 03:45:34 +0200 Subject: [PATCH] Add `missing` option to sequence.list DB method. If present and truthy, it will cause the output to contain two extra fields: missing_raw and missing_final, each consisting of a JSON array containing missing raw and final shots for the corresponding sequence. In the event that the option was passed but there are no missing shots, the two aforementioned fields will still be present and consist of empty arrays. Note that this makes the query significantly slower. --- lib/www/server/lib/db/sequence/list.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/www/server/lib/db/sequence/list.js b/lib/www/server/lib/db/sequence/list.js index fccaa89..afc1081 100644 --- a/lib/www/server/lib/db/sequence/list.js +++ b/lib/www/server/lib/db/sequence/list.js @@ -26,6 +26,12 @@ 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, + COALESCE((SELECT jsonb_agg(msfp) FROM missing_sequence_final_points msfp WHERE msfp.sequence = ss.sequence), '[]'::jsonb) missing_final` + : ""; const text = (opts.files ? ` @@ -45,14 +51,14 @@ async function list (projectId, opts = {}) { GROUP BY sequence ) SELECT - ss.*, + ss.*${missing_shots}, (SELECT files FROM rf WHERE rf.sequence = ss.sequence) raw_files, (SELECT files FROM ff WHERE ff.sequence = ss.sequence) final_files FROM sequences_summary ss ` : ` - SELECT * - FROM sequences_summary + SELECT ss.*${missing_shots} + FROM sequences_summary ss `) + ` WHERE