Migration and SQL-Optimizations

This commit is contained in:
int2001
2024-01-15 14:04:00 +00:00
parent e006e88b6d
commit f9a681a744
5 changed files with 69 additions and 8 deletions

View File

@@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
|
*/
$config['migration_version'] = 171;
$config['migration_version'] = 172;
/*
|--------------------------------------------------------------------------

View File

@@ -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();

View File

@@ -0,0 +1,61 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_main_index_cleanup extends CI_Migration {
public function up() {
$this->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);
}
}
}

View File

@@ -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);

View File

@@ -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 <> '' ";