Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape Wildcard Characters in get_filtering() method #135

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Large Resultset performance/memory leak
A first take on fixing the memory-leak/performance-issue when huge result-sets are queried.
chland committed Oct 13, 2017
commit fcedfa34b0addff88ddd1a664178920e79b3e5dd
51 changes: 47 additions & 4 deletions application/libraries/Datatables.php
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ class Datatables {
private $ci;
private $table;
private $distinct;
private $count_column;
private $group_by = array();
private $select = array();
private $joins = array();
@@ -313,6 +314,21 @@ public function or_like($field, $match = '', $side = 'both', $escape = NULL) {

}

/**
* Sets the column used for counting improving performance
*
* @param string $column
* @return mixed
*/

public function set_count_column($column) {

$this->count_column = $column;

return $this;

}

/**
* Sets additional column variables for adding custom columns
*
@@ -588,6 +604,10 @@ private function produce_output($output, $charset) {
/**
* Get result count
*
* @since 2.0.1 First attempt at fixing the poor performance for big tables.
* Takes some ideas from https://github.com/IgnitedDatatables/Ignited-Datatables/pull/122 and
* https://github.com/IgnitedDatatables/Ignited-Datatables/pull/94
*
* @param mixed $filtering
* @return integer
*/
@@ -630,13 +650,36 @@ private function get_total_results($filtering = false) {
}

if (strlen($this->distinct) > 0) {

$this->ci->db->distinct($this->distinct);
$this->ci->db->select($this->columns);
}
$this->ci->db->select($this->select);

} else {

if (strlen($this->count_column) > 0) {

$this->ci->db->select('COUNT('.$this->count_column.') AS num_rows');
$query = $this->ci->db->get(null, null, null, false);
$res = $query->result();

return $res[0]->num_rows;

} else {

$this->ci->db->select($this->select);

}

$query = $this->ci->db->get(null, null, null, false);

return $query->num_rows();
}

$subquery = $this->ci->db->get_compiled_select();
$countingsql = "SELECT COUNT(*) FROM (" . $subquery . ") SqueryAux";
$query = $this->ci->db->query($countingsql);
$result = $query->row_array();
$count = $result['COUNT(*)'];

return $count;

}