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

Datatables redesign client side cache mechanism #904

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions formats/datatables/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
$datatableData = $data['datatableData'];
$settings = $data['settings'];

if ( empty( $datatableData['length'] ) ) {
$datatableData['length'] = $settings['defer-each'];
}

if ( empty( $datatableData['start'] ) ) {
$datatableData['start'] = 0;
}
Expand Down Expand Up @@ -68,18 +64,17 @@
[
// *** important !!
'format' => 'datatables',
"apicall" => "apicall",
// @see https://datatables.net/manual/server-side
// array length will be sliced client side if greater
// than the required datatables length
"limit" => max( $datatableData['length'], $settings['defer-each'] ),
"offset" => $datatableData['start'],

"sort" => implode( ',', array_map( static function ( $value ) use( $datatableData ) {
'apicall' => 'apicall',

Check warning on line 67 in formats/datatables/Api.php

View check run for this annotation

Codecov / codecov/patch

formats/datatables/Api.php#L67

Added line #L67 was not covered by tests

// @TODO limit taking into account PreloaData
'limit' => max( $datatableData['length'], $settings['limit'] ),
'offset' => $datatableData['start'],

Check warning on line 71 in formats/datatables/Api.php

View check run for this annotation

Codecov / codecov/patch

formats/datatables/Api.php#L70-L71

Added lines #L70 - L71 were not covered by tests

'sort' => implode( ',', array_map( static function ( $value ) use( $datatableData ) {

Check warning on line 73 in formats/datatables/Api.php

View check run for this annotation

Codecov / codecov/patch

formats/datatables/Api.php#L73

Added line #L73 was not covered by tests
return $datatableData['columns'][$value['column']]['name'];
}, $datatableData['order'] ) ),

"order" => implode( ',', array_map( static function ( $value ) {
'order' => implode( ',', array_map( static function ( $value ) {

Check warning on line 77 in formats/datatables/Api.php

View check run for this annotation

Codecov / codecov/patch

formats/datatables/Api.php#L77

Added line #L77 was not covered by tests
return $value['dir'];
}, $datatableData['order'] ) )

Expand Down Expand Up @@ -298,7 +293,8 @@
'recordsTotal' => $settings['count'],
'recordsFiltered' => $count,
'cacheKey' => $data['cacheKey'],
'datalength' => $datatableData['length']
'datalength' => $datatableData['length'],
'start' => $datatableData['start']

Check warning on line 297 in formats/datatables/Api.php

View check run for this annotation

Codecov / codecov/patch

formats/datatables/Api.php#L296-L297

Added lines #L296 - L297 were not covered by tests
];

if ( $settings['displayLog'] ) {
Expand Down
7 changes: 3 additions & 4 deletions formats/datatables/DataTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ public function getParamDefinitions( array $definitions ) {
'values' => [ 'all', 'subject', 'none', 'auto' ],
];

$params['defer-each'] = [
$params['limit'] = [
'type' => 'integer',
'message' => 'smw-paramdesc-defer-each',
// $GLOBALS['smwgQMaxLimit']
'default' => 0,
'message' => 'smw-paramdesc-limit',
'default' => 100,
];

// *** only used internally, do not use in query
Expand Down
5 changes: 2 additions & 3 deletions formats/datatables/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@
}

$inlineLimit = $query->getLimit();

$count = self::getCount( $query, $queryEngine );
// $limit = ( !empty( $params['defer-each'] ) ? $params['defer-each'] : $inlineLimit );

if ( empty( $params['noajax'] ) ) {
// $lengthmenuMax = max( $params['datatables-lengthmenu'] );
$limit = max( $params['datatables-pagelength'], $params['defer-each'], $inlineLimit );
$limit = max( $params['datatables-pagelength'], $inlineLimit );

Check warning on line 41 in formats/datatables/Hooks.php

View check run for this annotation

Codecov / codecov/patch

formats/datatables/Hooks.php#L41

Added line #L41 was not covered by tests

} else {
$limit = $count;
Expand Down
Loading