From 6ff327ee699db81577a4aa196e636811567b140b Mon Sep 17 00:00:00 2001 From: int2001 Date: Tue, 3 Sep 2024 11:40:04 +0000 Subject: [PATCH 1/2] Tweak distance-records (filter by station at join as well) --- application/models/Distancerecords_model.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/models/Distancerecords_model.php b/application/models/Distancerecords_model.php index 4b6bde127..6014498b4 100644 --- a/application/models/Distancerecords_model.php +++ b/application/models/Distancerecords_model.php @@ -31,6 +31,7 @@ class Distancerecords_model extends CI_Model { LEFT JOIN ( SELECT *, ROW_NUMBER() OVER (PARTITION BY COL_SAT_NAME, COL_DISTANCE ORDER BY COL_TIME_ON asc) AS rn FROM '.$this->config->item('table_name').' + WHERE station_id IN ('.implode(', ', $logbooks_locations_array).') ) t2 ON t1.sat = t2.COL_SAT_NAME AND t1.distance = t2.COL_DISTANCE From ac45781c357a6c83e15259485455daa6900ffa74 Mon Sep 17 00:00:00 2001 From: int2001 Date: Tue, 3 Sep 2024 11:52:21 +0000 Subject: [PATCH 2/2] Use Bindings (faster for repeated queries) --- application/models/Distancerecords_model.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/application/models/Distancerecords_model.php b/application/models/Distancerecords_model.php index 6014498b4..4947450a4 100644 --- a/application/models/Distancerecords_model.php +++ b/application/models/Distancerecords_model.php @@ -59,17 +59,20 @@ class Distancerecords_model extends CI_Model { ORDER BY distance DESC;'; $query = $this->db->query($sql); - $result = array(); + $result = array(); // With that query for oldest QSO per sat and distance foreach ($query->result() as $row) { + $bindings=[]; $subsql = 'SELECT COL_SAT_NAME AS sat, COL_TIME_ON as time, COL_CALL as callsign, COL_GRIDSQUARE as grid, COL_MODE AS mode, COL_PRIMARY_KEY as primarykey FROM '.$this->config->item('table_name').' WHERE station_id IN ('.implode(', ', $logbooks_locations_array).') - AND COL_SAT_NAME = "'.$row->sat.'" - AND COL_DISTANCE = '.$row->distance.' + AND COL_SAT_NAME = ? + AND COL_DISTANCE = ? ORDER BY COL_TIME_ON ASC LIMIT 1;'; - $subquery = $this->db->query($subsql); + $bindings[]=$row->sat; + $bindings[]=$row->distance; + $subquery = $this->db->query($subsql, $bindings); $subrow = $subquery->row(); array_push($result, (object) ["sat" => $row->sat, "distance" => $row->distance, "time" => $subrow->time, "primarykey" => $subrow->primarykey, "callsign" => $subrow->callsign, "mode" => $subrow->mode, "grid" => $subrow->grid]); }