From 241d8429a437bd0947ff32c6b9b339de6ee7cefa Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Wed, 17 May 2023 12:10:11 +0100 Subject: [PATCH 1/3] LIMS-452: Speed up _get_all_containers --- api/src/Page/Shipment.php | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/api/src/Page/Shipment.php b/api/src/Page/Shipment.php index 722235486..58d3609a2 100644 --- a/api/src/Page/Shipment.php +++ b/api/src/Page/Shipment.php @@ -1680,7 +1680,7 @@ function _get_all_containers() } else if ($this->arg('ty') == 'processing') { $where .= " AND c.containerstatus = 'processing'"; } else if ($this->arg('ty') == 'subsamples') { - $having .= " HAVING COUNT(distinct ss.blsubsampleid) > 0"; + $having .= " HAVING subsamples > 0"; } } @@ -1705,6 +1705,7 @@ function _get_all_containers() if ($this->has_arg('pid')) { // $this->db->set_debug(True); + $join .= ' LEFT OUTER JOIN crystal cr ON cr.crystalid = s.crystalid LEFT OUTER JOIN protein pr ON pr.proteinid = cr.proteinid'; $where .= ' AND pr.proteinid=:' . (sizeof($args) + 1); array_push($args, $this->arg('pid')); } @@ -1799,7 +1800,7 @@ function _get_all_containers() if ($this->has_arg('sort_by')) { $cols = array( 'NAME' => 'c.code', 'DEWAR' => 'd.code', 'SHIPMENT' => 'sh.shippingname', 'SAMPLES' => 'count(s.blsampleid)', 'SHIPPINGID' => 'sh.shippingid', 'LASTINSPECTION' => 'max(ci.bltimestamp)', 'INSPECTIONS' => 'count(ci.containerinspectionid)', - 'DCCOUNT' => 'COUNT(distinct dc.datacollectionid)', 'SUBSAMPLES' => 'count(distinct ss.blsubsampleid)', + 'DCCOUNT' => 'COUNT(distinct dc.datacollectionid)', 'SUBSAMPLES' => 'subsamples', 'LASTQUEUECOMPLETED' => 'max(cq2.completedtimestamp)', 'QUEUEDTIMESTAMP' => 'max(cq.createdtimestamp)' ); $dir = $this->has_arg('order') ? ($this->arg('order') == 'asc' ? 'ASC' : 'DESC') : 'ASC'; @@ -1807,34 +1808,28 @@ function _get_all_containers() $order = $cols[$this->arg('sort_by')] . ' ' . $dir; } // $this->db->set_debug(True); - $rows = $this->db->paginate("SELECT round(TIMESTAMPDIFF('HOUR', min(ci.bltimestamp), CURRENT_TIMESTAMP)/24,1) as age, case when count(ci2.containerinspectionid) > 1 then 0 else 1 end as allow_adhoc, sch.name as schedule, c.scheduleid, c.screenid, sc.name as screen, c.imagerid, i.temperature as temperature, i.name as imager, TO_CHAR(max(ci.bltimestamp), 'HH24:MI DD-MM-YYYY') as lastinspection, round(TIMESTAMPDIFF('HOUR', max(ci.bltimestamp), CURRENT_TIMESTAMP)/24,1) as lastinspectiondays, count(distinct ci.containerinspectionid) as inspections, CONCAT(p.proposalcode, p.proposalnumber) as prop, c.bltimestamp, c.samplechangerlocation, c.beamlinelocation, d.dewarstatus, c.containertype, c.capacity, c.containerstatus, c.containerid, c.code as name, d.code as dewar, sh.shippingname as shipment, d.dewarid, sh.shippingid, count(distinct s.blsampleid) as samples, cq.containerqueueid, TO_CHAR(cq.createdtimestamp, 'DD-MM-YYYY HH24:MI') as queuedtimestamp, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), ses.visit_number) as visit, ses.beamlinename, c.requestedreturn, c.requestedimagerid, i2.name as requestedimager, c.comments, c.experimenttype, c.storagetemperature, c.barcode, reg.barcode as registry, reg.containerregistryid, - count(distinct ss.blsubsampleid) as subsamples, - ses3.beamlinename as firstexperimentbeamline, - pp.name as pipeline, + $rows = $this->db->paginate("SELECT round(TIMESTAMPDIFF('HOUR', min(ci.bltimestamp), CURRENT_TIMESTAMP)/24,1) as age, case when count(ci2.containerinspectionid) > 1 then 0 else 1 end as allow_adhoc, c.scheduleid, c.screenid, sc.name as screen, c.imagerid, i.temperature as temperature, i.name as imager, TO_CHAR(max(ci.bltimestamp), 'HH24:MI DD-MM-YYYY') as lastinspection, round(TIMESTAMPDIFF('HOUR', max(ci.bltimestamp), CURRENT_TIMESTAMP)/24,1) as lastinspectiondays, count(distinct ci.containerinspectionid) as inspections, CONCAT(p.proposalcode, p.proposalnumber) as prop, c.bltimestamp, c.samplechangerlocation, c.beamlinelocation, d.dewarstatus, c.containertype, c.capacity, c.containerstatus, c.containerid, c.code as name, d.code as dewar, sh.shippingname as shipment, d.dewarid, sh.shippingid, count(distinct s.blsampleid) as samples, cq.containerqueueid, TO_CHAR(cq.createdtimestamp, 'DD-MM-YYYY HH24:MI') as queuedtimestamp, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), ses.visit_number) as visit, ses.beamlinename, c.requestedreturn, c.requestedimagerid, c.comments, c.experimenttype, c.storagetemperature, c.barcode, reg.barcode as registry, reg.containerregistryid, + (SELECT sch.name FROM schedule sch WHERE sch.scheduleid = c.scheduleid) as schedule, + (SELECT i2.name FROM imager i2 WHERE i2.imagerid = c.requestedimagerid) as requestedimager, + (SELECT count(distinct ss.blsubsampleid) FROM blsubsample ss RIGHT OUTER JOIN blsample s2 ON s2.blsampleid = ss.blsampleid WHERE s2.containerid = c.containerid AND ss.source='manual') as subsamples, + (SELECT ses3.beamlinename FROM blsession ses3 WHERE d.firstexperimentid = ses3.sessionid) as firstexperimentbeamline, + (SELECT pp.name FROM processingpipeline pp WHERE c.prioritypipelineid = pp.processingpipelineid) as pipeline, TO_CHAR(max(cq2.completedtimestamp), 'HH24:MI DD-MM-YYYY') as lastqueuecompleted, TIMESTAMPDIFF('MINUTE', max(cq2.completedtimestamp), max(cq2.createdtimestamp)) as lastqueuedwell, - c.ownerid, CONCAT(pe.givenname, ' ', pe.familyname) as owner + c.ownerid, + (SELECT CONCAT(pe.givenname, ' ', pe.familyname) FROM person pe WHERE c.ownerid = pe.personid) FROM container c INNER JOIN dewar d ON d.dewarid = c.dewarid - LEFT OUTER JOIN blsession ses3 ON d.firstexperimentid = ses3.sessionid INNER JOIN shipping sh ON sh.shippingid = d.shippingid INNER JOIN proposal p ON p.proposalid = sh.proposalid LEFT OUTER JOIN blsample s ON s.containerid = c.containerid - LEFT OUTER JOIN blsubsample ss ON s.blsampleid = ss.blsampleid AND ss.source='manual' - LEFT OUTER JOIN crystal cr ON cr.crystalid = s.crystalid - LEFT OUTER JOIN protein pr ON pr.proteinid = cr.proteinid LEFT OUTER JOIN containerinspection ci ON ci.containerid = c.containerid AND ci.state = 'Completed' LEFT OUTER JOIN imager i ON i.imagerid = c.imagerid - LEFT OUTER JOIN imager i2 ON i2.imagerid = c.requestedimagerid LEFT OUTER JOIN screen sc ON sc.screenid = c.screenid - LEFT OUTER JOIN schedule sch ON sch.scheduleid = c.scheduleid LEFT OUTER JOIN containerinspection ci2 ON ci2.containerid = c.containerid AND ci2.state != 'Completed' AND ci2.manual!=1 AND ci2.schedulecomponentid IS NULL LEFT OUTER JOIN containerqueue cq ON cq.containerid = c.containerid AND cq.completedtimestamp IS NULL LEFT OUTER JOIN containerqueue cq2 ON cq2.containerid = c.containerid AND cq2.completedtimestamp IS NOT NULL LEFT OUTER JOIN containerregistry reg ON reg.containerregistryid = c.containerregistryid - LEFT OUTER JOIN blsession ses ON c.sessionid = ses.sessionid - LEFT OUTER JOIN processingpipeline pp ON c.prioritypipelineid = pp.processingpipelineid - LEFT OUTER JOIN person pe ON c.ownerid = pe.personid $join WHERE $where From d3fd07a59b6124642c9e31695f307eec975499d1 Mon Sep 17 00:00:00 2001 From: Mark W <24956497+ndg63276@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:08:19 +0100 Subject: [PATCH 2/3] Update api/src/Page/Shipment.php Co-authored-by: John Holt <7570055+John-Holt-Tessella@users.noreply.github.com> --- api/src/Page/Shipment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/Page/Shipment.php b/api/src/Page/Shipment.php index 58d3609a2..b812c6f45 100644 --- a/api/src/Page/Shipment.php +++ b/api/src/Page/Shipment.php @@ -1816,7 +1816,7 @@ function _get_all_containers() (SELECT pp.name FROM processingpipeline pp WHERE c.prioritypipelineid = pp.processingpipelineid) as pipeline, TO_CHAR(max(cq2.completedtimestamp), 'HH24:MI DD-MM-YYYY') as lastqueuecompleted, TIMESTAMPDIFF('MINUTE', max(cq2.completedtimestamp), max(cq2.createdtimestamp)) as lastqueuedwell, c.ownerid, - (SELECT CONCAT(pe.givenname, ' ', pe.familyname) FROM person pe WHERE c.ownerid = pe.personid) + (SELECT CONCAT(pe.givenname, ' ', pe.familyname) FROM person pe WHERE c.ownerid = pe.personid) as owner FROM container c INNER JOIN dewar d ON d.dewarid = c.dewarid INNER JOIN shipping sh ON sh.shippingid = d.shippingid From d3349a06baa8e4319d9fe1159d0b0f3a396b1f1d Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Wed, 16 Aug 2023 11:13:15 +0100 Subject: [PATCH 3/3] Fix bug with 'Has subsamples' filter --- api/src/Page/Shipment.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/Page/Shipment.php b/api/src/Page/Shipment.php index b812c6f45..e2814b07e 100644 --- a/api/src/Page/Shipment.php +++ b/api/src/Page/Shipment.php @@ -1750,7 +1750,8 @@ function _get_all_containers() array_push($args, $this->user->personId); } - $tot = $this->db->pq("SELECT count(distinct c.containerid) as tot + $tot = $this->db->pq("SELECT count(distinct c.containerid) as tot, + count(distinct ss.blsubsampleid) as subsamples FROM container c INNER JOIN dewar d ON d.dewarid = c.dewarid INNER JOIN shipping sh ON sh.shippingid = d.shippingid