Skip to content

Commit

Permalink
Fix slow data collection queries (#726)
Browse files Browse the repository at this point in the history
Looks good to me
  • Loading branch information
gfrn authored Feb 12, 2024
1 parent 1f07ec5 commit c18e3a0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions api/src/Page/DC.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function _data_collections($single = null)
$where = " AND appm.autoprocprogrammessageid IS NOT NULL AND (appm.severity = 'WARNING' OR appm.severity = 'ERROR')";
$extj[0] .= "LEFT OUTER JOIN autoprocintegration api ON dc.datacollectionid = api.datacollectionid
LEFT OUTER JOIN processingjob pj ON dc.datacollectionid = pj.datacollectionid
LEFT OUTER JOIN autoprocprogram app ON (app.autoprocprogramid = api.autoprocprogramid OR dc.datacollectionid = pj.datacollectionid)
LEFT OUTER JOIN autoprocprogram app ON app.autoprocprogramid = api.autoprocprogramid
INNER JOIN autoprocprogrammessage appm ON appm.autoprocprogramid = app.autoprocprogramid";
} else if ($this->arg('t') == "scrystal" || $this->arg('t') == "nscrystal") {
// Single crystal or explicitly non-single-crystal fields
Expand Down Expand Up @@ -615,6 +615,7 @@ function _data_collections($single = null)
$groupby = "GROUP BY dc.datacollectiongroupid";
}

// We don't want to remove duplicates, since if two counts are equal, one might go uncounted
$total_query = "SELECT sum(tot) as t FROM (
$with
SELECT count($count_field) as tot
Expand All @@ -625,21 +626,21 @@ function _data_collections($single = null)
$extj[0]
WHERE $sess[0] $where
UNION SELECT count(es.energyscanid) as tot
UNION ALL SELECT count(es.energyscanid) as tot
FROM energyscan es
INNER JOIN blsession ses ON ses.sessionid = es.sessionid
$sample_joins[1]
$extj[1]
WHERE $sess[1] $where2
UNION SELECT count(xrf.xfefluorescencespectrumid) as tot
UNION ALL SELECT count(xrf.xfefluorescencespectrumid) as tot
FROM xfefluorescencespectrum xrf
INNER JOIN blsession ses ON ses.sessionid = xrf.sessionid
$sample_joins[3]
$extj[3]
WHERE $sess[3] $where4
UNION SELECT count(r.robotactionid) as tot
UNION ALL SELECT count(r.robotactionid) as tot
FROM robotaction r
INNER JOIN blsession ses ON ses.sessionid = r.blsessionid
$sample_joins[2]
Expand Down

0 comments on commit c18e3a0

Please sign in to comment.