From 5042ce3f8cee215f19ac2d4add3c6511cb878280 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 6 Apr 2020 23:58:26 +0100 Subject: [PATCH] Benchmarking data added to controller function and new callsign lookup call to speed up load times --- application/controllers/Api.php | 17 +++++++++++------ application/models/Logbook_model.php | 27 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 922ae3fc..9e1d49bc 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -497,6 +497,8 @@ class API extends CI_Controller { } function lookup() { + // start benchmarking + $this->output->enable_profiler(TRUE); /* * * Callsign lookup function for Cloudlogs logging page or thirdparty systems @@ -606,14 +608,15 @@ class API extends CI_Controller { * Pool any local data we have for a callsign * */ + $call_lookup_results = $this->logbook_model->call_lookup_result($lookup_callsign); - if($this->logbook_model->call_name($lookup_callsign) != null) + if($call_lookup_results != null) { - $return['name'] = $this->logbook_model->call_name($lookup_callsign); - $return['gridsquare'] = $this->logbook_model->call_qra($lookup_callsign); - $return['location'] = $this->logbook_model->call_qth($lookup_callsign); - $return['iota_ref'] = $this->logbook_model->call_iota($lookup_callsign); - $return['qsl_manager'] = $this->logbook_model->call_qslvia($lookup_callsign); + $return['name'] = $call_lookup_results->COL_NAME; + $return['gridsquare'] = $call_lookup_results->COL_GRIDSQUARE; + $return['location'] = $call_lookup_results->COL_QTH; + $return['iota_ref'] = $call_lookup_results->COL_IOTA; + $return['qsl_manager'] = $call_lookup_results->COL_QSL_VIA; if ($return['gridsquare'] != "") { $return['latlng'] = $this->qralatlng($return['gridsquare']); @@ -644,6 +647,8 @@ class API extends CI_Controller { echo json_encode($return, JSON_PRETTY_PRINT); return; + // End benchmarking + $this->output->enable_profiler(FALSE); } function qralatlng($qra) { diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 2c473c49..1a29f709 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -378,8 +378,33 @@ class Logbook_model extends CI_Model { return $this->db->get($this->config->item('table_name')); } - /* Callsign QRA */ + /* + * + * Function: call_lookup_result + * + * Usage: Callsign lookup data for the QSO panel and API/callsign_lookup + * + */ + function call_lookup_result($callsign) { + $this->db->select('COL_CALL, COL_NAME, COL_QSL_VIA, COL_GRIDSQUARE, COL_QTH, COL_IOTA, COL_TIME_ON'); + $this->db->where('COL_CALL', $callsign); + $where = "COL_NAME != \"\""; + $this->db->where($where); + + $this->db->order_by("COL_TIME_ON", "desc"); + $this->db->limit(1); + $query = $this->db->get($this->config->item('table_name')); + $name = ""; + if ($query->num_rows() > 0) + { + $data = $query->row(); + } + + return $data; + } + + /* Callsign QRA */ function call_qra($callsign) { $this->db->select('COL_CALL, COL_GRIDSQUARE, COL_TIME_ON'); $this->db->where('COL_CALL', $callsign);