Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
jippi committed May 31, 2014
1 parent a2329a0 commit db92e2f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
29 changes: 13 additions & 16 deletions Controller/AuditsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,27 @@ public function beforeFilter() {
}

public function admin_index() {
$this->Paginator->settings['fields'] = [
'Audit.id',
'Audit.event',
'Audit.model',
'Audit.entity_id',
'Audit.description',
'Audit.source_id',
'Audit.created',
'Audit.delta_count',
];

$this->Crud->on('beforePaginate', function($event) {
if ($model = $this->request->query('model')) {
$Instance = ClassRegistry::init($model);

$displayField = $Instance->displayField;

$this->Paginator->settings['fields'] = [
'Audit.id',
'Audit.event',
'Audit.model',
'Audit.entity_id',
'Audit.description',
'Audit.source_id',
'Audit.created',
'Audit.delta_count',
$model . '.' . $displayField
];

$this->Paginator->settings['fields'][] = $model . '.' . $displayField;
$this->Paginator->settings['joins'][] = [
'alias' => $model,
'table' => $Instance->useTable,
'conditions' => [
$Instance->alias . '.id = Audit.entity_id'
],
'conditions' => [$Instance->alias . '.id = Audit.entity_id'],
'type' => 'INNER'
];

Expand Down
12 changes: 12 additions & 0 deletions Model/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,16 @@ public function setupSearchPlugin() {
$this->Behaviors->load('Search.Searchable');
}

/**
* Make sure not to include any join's in the COUNT(*) from paginator
*
* @param array $conditions
* @param integer $recursive
* @param array $extra
* @return integer
*/
public function paginateCount($conditions, $recursive, $extra) {
return $this->find('count', compact('conditions'));
}

}

0 comments on commit db92e2f

Please sign in to comment.