[Awards CQ] Added index for speedup. Removed some unused code and reduced number of queries by a few.

pull/968/head
Andreas 2021-03-27 14:28:29 +01:00
rodzic 51ff9c1734
commit 5979cceb33
5 zmienionych plików z 42 dodań i 31 usunięć

Wyświetl plik

@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 66;
$config['migration_version'] = 67;
/*
|--------------------------------------------------------------------------

Wyświetl plik

@ -213,14 +213,13 @@ class Awards extends CI_Controller {
}
public function cq(){
$this->load->model('cq');
$zones = array();
foreach($this->cq->get_zones() as $row){
array_push($zones, intval($row->COL_CQZ));
}
$data['cqz'] = $zones;
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
$data['worked_bands'] = $this->cq->get_worked_bands();
$this->load->model('cq');
$data['worked_bands'] = $this->cq->get_worked_bands($station_id);
if ($this->input->post('band') != NULL) { // Band is not set when page first loads.
if ($this->input->post('band') == 'All') { // Did the user specify a band? If not, use all bands
@ -253,8 +252,8 @@ class Awards extends CI_Controller {
$postdata['band'] = 'All';
}
$data['cq_array'] = $this->cq->get_cq_array($bands, $postdata);
$data['cq_summary'] = $this->cq->get_cq_summary($bands);
$data['cq_array'] = $this->cq->get_cq_array($bands, $postdata, $station_id);
$data['cq_summary'] = $this->cq->get_cq_summary($data['worked_bands'], $station_id);
// Render page
$data['page_title'] = "Awards - CQ Magazine";

Wyświetl plik

@ -0,0 +1,24 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
* This migration creates a table called options which will hold global options needed within cloudlog
* removing the need for lots of configuration files.
*/
class Migration_add_index_cqz_prop extends CI_Migration {
public function up()
{
$sql = "ALTER TABLE ".$this->config->item('table_name')." ADD INDEX `HRD_IDX_COL_CQZ` (`COL_CQZ`);";
$this->db->query($sql);
$sql = "ALTER TABLE ".$this->config->item('table_name')." ADD INDEX `HRD_IDX_COL_PROP_MODE` (`COL_PROP_MODE`);";
$this->db->query($sql);
}
public function down()
{
}
}

Wyświetl plik

@ -15,7 +15,7 @@ class CQ extends CI_Model{
$data = $this->db->query(
"select COL_CQZ, count(COL_CQZ)
from ".$this->config->item('table_name')."
where COL_CQZ is not null and station_id = ".$station_id."
where COL_CQZ is not null and station_id = ".$station_id."
group by COL_CQZ order by COL_CQZ"
);
@ -45,12 +45,8 @@ class CQ extends CI_Model{
"SAT" => 0,
);
function get_worked_bands()
function get_worked_bands($station_id)
{
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
// get all worked slots from database
$data = $this->db->query(
"SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `" . $this->config->item('table_name') . "` WHERE station_id = " . $station_id . " AND COL_PROP_MODE != \"SAT\""
@ -78,11 +74,7 @@ class CQ extends CI_Model{
return $results;
}
function get_cq_array($bands, $postdata) {
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
function get_cq_array($bands, $postdata, $station_id) {
$cqZ = array(); // Used for keeping track of which states that are not worked
for ($i = 1; $i <= 40; $i++) {
@ -146,7 +138,7 @@ class CQ extends CI_Model{
* $postdata contains data from the form, in this case Lotw or QSL are used
*/
function getCQWorked($station_id, $band, $postdata) {
$sql = "SELECT distinct col_cqz FROM " . $this->config->item('table_name') . " thcv
$sql = "SELECT distinct col_cqz FROM " . $this->config->item('table_name') . " thcv
where station_id = " . $station_id . " and col_cqz <> ''";
$sql .= $this->addBandToQuery($band);
@ -171,7 +163,7 @@ class CQ extends CI_Model{
* $postdata contains data from the form, in this case Lotw or QSL are used
*/
function getCQConfirmed($station_id, $band, $postdata) {
$sql = "SELECT distinct col_cqz FROM " . $this->config->item('table_name') . " thcv
$sql = "SELECT distinct col_cqz FROM " . $this->config->item('table_name') . " thcv
where station_id = " . $station_id . " and col_cqz <> ''";
$sql .= $this->addBandToQuery($band);
@ -215,11 +207,7 @@ class CQ extends CI_Model{
/*
* Function gets worked and confirmed summary on each band on the active stationprofile
*/
function get_cq_summary($bands) {
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
function get_cq_summary($bands, $station_id) {
foreach ($bands as $band) {
$worked = $this->getSummaryByBand($band, $station_id);
$confirmed = $this->getSummaryByBandConfirmed($band, $station_id);

Wyświetl plik

@ -134,8 +134,8 @@
<div class="form-group row">
<label class="col-md-2 control-label" for="button1id"></label>
<div class="col-md-10">
<button id="button2id" type="reset" name="button2id" class="btn btn-warning">Reset</button>
<button id="button1id" type="submit" name="button1id" class="btn btn-primary">Show</button>
<button id="button2id" type="reset" name="button2id" class="btn-sm btn-warning">Reset</button>
<button id="button1id" type="submit" name="button1id" class="btn-sm btn-primary">Show</button>
</div>
</div>
@ -172,7 +172,7 @@
<thead>
<tr><td></td>';
foreach($bands as $band) {
foreach($worked_bands as $band) {
echo '<td>' . $band . '</td>';
}
echo '<td>Total</td></tr>