From e006e88b6d6da4e6903d4fc17b5b02d680be1d88 Mon Sep 17 00:00:00 2001 From: int2001 Date: Mon, 15 Jan 2024 08:27:34 +0000 Subject: [PATCH 1/4] Altred SQL for Overview. Speedup-factor 5 --- application/models/Logbook_model.php | 47 ++++++++++++++-------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 95bbb1666..ab533141b 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1620,35 +1620,34 @@ class Logbook_model extends CI_Model { } function get_qsos($num, $offset, $StationLocationsArray = null) { - if($StationLocationsArray == null) { - $CI =& get_instance(); - $CI->load->model('logbooks_model'); - $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - } else { - $logbooks_locations_array = $StationLocationsArray; - } + if(ENVIRONMENT == 'development') { + $this->output->enable_profiler(TRUE); + } + if($StationLocationsArray == null) { + $CI =& get_instance(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + } else { + $logbooks_locations_array = $StationLocationsArray; + } - if (empty($logbooks_locations_array)) { - return array(); - } + if (empty($logbooks_locations_array)) { + return array(); + } - $this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.*, lotw_users.callsign, lotw_users.lastupload'); - $this->db->from($this->config->item('table_name')); + $this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.*, lotw_users.callsign, lotw_users.lastupload'); + $this->db->from($this->config->item('table_name')); - // remove anything thats duplicated based on COL_PRIMARY_KEY - $this->db->distinct(''.$this->config->item('table_name').'.COL_PRIMARY_KEY'); + $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); + $this->db->join('dxcc_entities', $this->config->item('table_name').'.col_dxcc = dxcc_entities.adif', 'left'); + $this->db->join('lotw_users', 'lotw_users.callsign = '.$this->config->item('table_name').'.col_call', 'left outer'); + $this->db->where_in('station_profile.station_id', $logbooks_locations_array); + $this->db->order_by(''.$this->config->item('table_name').'.COL_TIME_ON', "desc"); - $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); - $this->db->join('dxcc_entities', $this->config->item('table_name').'.col_dxcc = dxcc_entities.adif', 'left'); - $this->db->join('lotw_users', 'lotw_users.callsign = '.$this->config->item('table_name').'.col_call', 'left outer'); - $this->db->where_in('station_profile.station_id', $logbooks_locations_array); - $this->db->order_by(''.$this->config->item('table_name').'.COL_TIME_ON', "desc"); - $this->db->order_by(''.$this->config->item('table_name').'.COL_PRIMARY_KEY', "desc"); + $this->db->limit($num); + $this->db->offset($offset); - $this->db->limit($num); - $this->db->offset($offset); - - return $this->db->get(); + return $this->db->get(); } function get_qso($id, $trusted = false) { From f9a681a744bcf7ff9f6da395483db5c9b3895d32 Mon Sep 17 00:00:00 2001 From: int2001 Date: Mon, 15 Jan 2024 14:04:00 +0000 Subject: [PATCH 2/4] Migration and SQL-Optimizations --- application/config/migration.php | 2 +- application/controllers/Qso.php | 1 + .../migrations/172_main_index_cleanup.php | 61 +++++++++++++++++++ application/models/Logbook_model.php | 11 ++-- application/models/Vucc.php | 2 +- 5 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 application/migrations/172_main_index_cleanup.php diff --git a/application/config/migration.php b/application/config/migration.php index 7ba70516d..8e09e94f4 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 171; +$config['migration_version'] = 172; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 0463722be..6081ea82e 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -583,6 +583,7 @@ class QSO extends CI_Controller { // Return Previous QSOs Made in the active logbook public function component_past_contacts() { + $this->output->enable_profiler(TRUE); if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } $this->load->model('logbook_model'); session_write_close(); diff --git a/application/migrations/172_main_index_cleanup.php b/application/migrations/172_main_index_cleanup.php new file mode 100644 index 000000000..c9da3a1f2 --- /dev/null +++ b/application/migrations/172_main_index_cleanup.php @@ -0,0 +1,61 @@ +rm_ix('HRD_IDX_COL_CQZ'); + $this->rm_ix('gridsquares'); + $this->rm_ix('station_id'); + $this->rm_ix('HRD_IDX_COL_BAND'); + $this->rm_ix('HRD_IDX_COL_CALL'); + $this->rm_ix('HRD_IDX_COL_CONT'); + $this->rm_ix('HRD_IDX_COL_DXCC'); + $this->rm_ix('HRD_IDX_COL_IOTA'); + $this->rm_ix('HRD_IDX_COL_MODE'); + $this->rm_ix('HRD_IDX_COL_PFX'); + $this->rm_ix('HRD_IDX_COL_TIME_ON'); + $this->add_ix('idx_HRD_DBL_CHK','`station_id`, `COL_CALL`,`COL_BAND`,`COL_MODE`'); + $this->add_ix('idx_HRD_COL_BAND_station_id','`station_id`,`COL_BAND`,`COL_TIME_ON` desc'); + $this->add_ix('idx_HRD_COL_CALL_station_id','`station_id`,`COL_CALL`,`COL_TIME_ON` desc'); + $this->add_ix('idx_HRD_COL_DXCC_station_id','`station_id`,`COL_DXCC`,`COL_TIME_ON` desc'); + $this->add_ix('idx_HRD_station_id','`station_id`,`COL_TIME_ON` desc'); + } + + + public function down(){ + $this->rm_ix('idx_HRD_DBL_CHK'); + $this->rm_ix('idx_HRD_COL_BAND_station_id'); + $this->rm_ix('idx_HRD_COL_CALL_station_id'); + $this->rm_ix('idx_HRD_COL_DXCC_station_id'); + $this->rm_ix('idx_HRD_station_id'); + $this->add_ix('HRD_IDX_COL_CQZ','`COL_CQZ`'); + $this->add_ix('gridsquares','`COL_GRIDSQUARE`'); + $this->add_ix('station_id','`station_id`'); + $this->add_ix('HRD_IDX_COL_BAND','`COL_BAND`'); + $this->add_ix('HRD_IDX_COL_CALL','`COL_CALL`'); + $this->add_ix('HRD_IDX_COL_CONT','`COL_CONT`'); + $this->add_ix('HRD_IDX_COL_DXCC','`COL_DXCC`'); + $this->add_ix('HRD_IDX_COL_IOTA','`COL_IOTA`'); + $this->add_ix('HRD_IDX_COL_MODE','`COL_MODE`'); + $this->add_ix('HRD_IDX_COL_PFX','`COL_PFX`'); + $this->add_ix('HRD_IDX_COL_TIME_ON','`COL_TIME_ON`'); + } + + private function add_ix($index,$cols) { + $ix_exist = $this->db->query("SHOW INDEX FROM ".$this->config->item('table_name')." WHERE Key_name = '".$index."'")->num_rows(); + if ($ix_exist == 0) { + $sql = "ALTER TABLE ".$this->config->item('table_name')." ADD INDEX `".$index."` (".$cols.");"; + $this->db->query($sql); + } + } + + private function rm_ix($index) { + $ix_exist = $this->db->query("SHOW INDEX FROM ".$this->config->item('table_name')." WHERE Key_name = '".$index."'")->num_rows(); + if ($ix_exist >= 1) { + $sql = "ALTER TABLE ".$this->config->item('table_name')." DROP INDEX `".$index."`;"; + $this->db->query($sql); + } + } +} diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index ab533141b..fda1923da 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1263,9 +1263,8 @@ class Logbook_model extends CI_Model { /* Show custom number of qsos */ function last_custom($num) { - $CI =& get_instance(); - $CI->load->model('logbooks_model'); - $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); if(!empty($logbooks_locations_array)) { $this->db->select('COL_CALL, COL_BAND, COL_FREQ, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_SUBMODE, COL_NAME, COL_COUNTRY, COL_DXCC, COL_PRIMARY_KEY, COL_SAT_NAME, COL_SRX, COL_SRX_STRING, COL_STX, COL_STX_STRING, COL_VUCC_GRIDS, COL_GRIDSQUARE, COL_MY_GRIDSQUARE, COL_OPERATOR, COL_IOTA, COL_WWFF_REF, COL_POTA_REF, COL_STATE, COL_CNTY, COL_DISTANCE, COL_SOTA_REF, COL_CONTEST_ID, dxcc_entities.end AS end'); @@ -1641,7 +1640,7 @@ class Logbook_model extends CI_Model { $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); $this->db->join('dxcc_entities', $this->config->item('table_name').'.col_dxcc = dxcc_entities.adif', 'left'); $this->db->join('lotw_users', 'lotw_users.callsign = '.$this->config->item('table_name').'.col_call', 'left outer'); - $this->db->where_in('station_profile.station_id', $logbooks_locations_array); + $this->db->where_in($this->config->item('table_name').'.station_id', $logbooks_locations_array); $this->db->order_by(''.$this->config->item('table_name').'.COL_TIME_ON', "desc"); $this->db->limit($num); @@ -1848,12 +1847,12 @@ class Logbook_model extends CI_Model { $sql = "SELECT * FROM ( select * from " . $this->config->item('table_name'). " WHERE station_id IN(". $location_list .") - order by col_time_on desc, col_primary_key desc + order by col_time_on desc limit " . $num . ") hrd JOIN station_profile ON station_profile.station_id = hrd.station_id LEFT JOIN dxcc_entities ON hrd.col_dxcc = dxcc_entities.adif - order by col_time_on desc, col_primary_key desc"; + order by col_time_on desc"; $query = $this->db->query($sql); diff --git a/application/models/Vucc.php b/application/models/Vucc.php index 1d67bc3a2..5ef1343fe 100644 --- a/application/models/Vucc.php +++ b/application/models/Vucc.php @@ -110,7 +110,7 @@ class VUCC extends CI_Model $location_list = "'".implode("','",$logbooks_locations_array)."'"; - $sql = "select col_vucc_grids + $sql = "select distinct col_vucc_grids from " . $this->config->item('table_name') . " where station_id in (" . $location_list . ")" . " and col_vucc_grids <> '' "; From 967553234bfc5a18bd68b3d916b008f1de2c79f9 Mon Sep 17 00:00:00 2001 From: int2001 Date: Mon, 15 Jan 2024 14:04:55 +0000 Subject: [PATCH 3/4] Disable Profiler --- application/controllers/Qso.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 6081ea82e..0463722be 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -583,7 +583,6 @@ class QSO extends CI_Controller { // Return Previous QSOs Made in the active logbook public function component_past_contacts() { - $this->output->enable_profiler(TRUE); if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } $this->load->model('logbook_model'); session_write_close(); From a842f878e260cf2cd24f16fae4ac37524dcf559f Mon Sep 17 00:00:00 2001 From: int2001 Date: Mon, 15 Jan 2024 14:44:23 +0000 Subject: [PATCH 4/4] Changed Mig-Number, since @phl0 was quicker --- application/config/migration.php | 2 +- .../{172_main_index_cleanup.php => 173_main_index_cleanup.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename application/migrations/{172_main_index_cleanup.php => 173_main_index_cleanup.php} (100%) diff --git a/application/config/migration.php b/application/config/migration.php index 8e09e94f4..7bdc9b407 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 172; +$config['migration_version'] = 173; /* |-------------------------------------------------------------------------- diff --git a/application/migrations/172_main_index_cleanup.php b/application/migrations/173_main_index_cleanup.php similarity index 100% rename from application/migrations/172_main_index_cleanup.php rename to application/migrations/173_main_index_cleanup.php