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/173_main_index_cleanup.php b/application/migrations/173_main_index_cleanup.php new file mode 100644 index 000000000..c9da3a1f2 --- /dev/null +++ b/application/migrations/173_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 ceb940af1..2400aa170 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1617,23 +1617,23 @@ class Logbook_model extends CI_Model { 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')); + if (empty($logbooks_locations_array)) { + return array(); + } - // remove anything thats duplicated based on COL_PRIMARY_KEY - $this->db->distinct(''.$this->config->item('table_name').'.COL_PRIMARY_KEY'); + $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->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->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($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); - $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) { @@ -1832,12 +1832,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 <> '' ";