Skip to content

Commit

Permalink
Update Datatables.php
Browse files Browse the repository at this point in the history
Big fix to get_total_results function.  This passed the years and nobody realised that this function was counting all the records on selects, consuming huge amounts of memory (sometimes throwing OUT OF MEMORY) when working with big tables, and giving the impression the pagination was not working.
  • Loading branch information
scorpile authored Feb 8, 2017
1 parent 943e058 commit 85ebb6a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions application/libraries/Datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,12 @@ private function get_total_results($filtering = FALSE)
$this->ci->db->distinct($this->distinct);
$this->ci->db->select($this->columns);
}

$query = $this->ci->db->get($this->table, NULL, NULL, FALSE);
return $query->num_rows();
$subquery = $this->ci->db->get_compiled_select($this->table);
$countingsql = "SELECT COUNT(*) FROM (" . $subquery . ") SqueryAux";
$query = $this->ci->db->query($countingsql);
$result = $query->row_array();
$count = $result['COUNT(*)'];
return $count;
}

/**
Expand Down

0 comments on commit 85ebb6a

Please sign in to comment.