Skip to content

Commit 2e1b422

Browse files
committed
Improve performance for searching & ordering
Only count the field names length once
1 parent c5d686f commit 2e1b422

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/DataTables.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ protected function filter()
157157
$globalSearch = [];
158158
$columnSearch = [];
159159

160+
$fieldNamesLength = count($this->returnedFieldNames);
161+
160162
// Global column filtering
161163
if ($this->request->get('search') && ($keyword = $this->request->get('search')['value']) != '') {
162164
foreach ($this->request->get('columns') as $request_column) {
@@ -170,7 +172,6 @@ protected function filter()
170172
$fieldIndex = $this->sequenceNumber ? $column - 1 : $column;
171173

172174
// Skip extra column
173-
$fieldNamesLength = count($this->returnedFieldNames);
174175
if ($fieldIndex > $fieldNamesLength - 1) break;
175176

176177
$column = $this->returnedFieldNames[$fieldIndex];
@@ -201,7 +202,6 @@ protected function filter()
201202
$fieldIndex = $this->sequenceNumber ? $column - 1 : $column;
202203

203204
// Skip extra column
204-
$fieldNamesLength = count($this->returnedFieldNames);
205205
if ($fieldIndex > $fieldNamesLength - 1) break;
206206

207207
$column = $this->returnedFieldNames[$fieldIndex];
@@ -243,6 +243,8 @@ protected function order()
243243
{
244244
if ($this->request->get('order') && count($this->request->get('order'))) {
245245
$orders = [];
246+
$fieldNamesLength = count($this->returnedFieldNames);
247+
246248
foreach ($this->request->get('order') as $order) {
247249
$column_idx = $order['column'];
248250
$request_column = $this->request->get('columns')[$column_idx];
@@ -257,7 +259,6 @@ protected function order()
257259
$fieldIndex = $this->sequenceNumber ? $column - 1 : $column;
258260

259261
// Skip extra column
260-
$fieldNamesLength = count($this->returnedFieldNames);
261262
if ($fieldIndex > $fieldNamesLength - 1) break;
262263

263264
$column = $this->returnedFieldNames[$fieldIndex];

0 commit comments

Comments
 (0)