Skip to content

Commit

Permalink
Table: performance, prevents multiple parse of query parts by regexp (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
norbe authored and dg committed May 7, 2016
1 parent 31e1b1c commit e5a9b9e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Database/Table/GroupedSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function order($columns, ...$params)

public function aggregation($function)
{
$aggregation = & $this->getRefTable($refPath)->aggregation[$refPath . $function . $this->getSql() . json_encode($this->sqlBuilder->getParameters())];
$aggregation = & $this->getRefTable($refPath)->aggregation[$refPath . $function . $this->sqlBuilder->getSelectQueryHash($this->getPreviousAccessedColumns())];

if ($aggregation === NULL) {
$aggregation = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Table/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ protected function getSpecificCacheKey()
return $this->specificCacheKey;
}

return $this->specificCacheKey = md5($this->getSql() . json_encode($this->sqlBuilder->getParameters()));
return $this->specificCacheKey = $this->sqlBuilder->getSelectQueryHash($this->getPreviousAccessedColumns());
}


Expand Down
33 changes: 33 additions & 0 deletions src/Database/Table/SqlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,39 @@ public function buildDeleteQuery()
}


/**
* Returns select query hash for caching.
* @return string
*/
public function getSelectQueryHash($columns = NULL)
{
$parts = [
'delimitedTable' => $this->delimitedTable,
'queryCondition' => $this->buildConditions(),
'queryEnd' => $this->buildQueryEnd(),
$this->aliases,
$this->limit, $this->offset,
];
if ($this->select) {
$parts[] = $this->select;
} elseif ($columns) {
$parts[] = [$this->delimitedTable, $columns];
} elseif ($this->group && !$this->driver->isSupported(ISupplementalDriver::SUPPORT_SELECT_UNGROUPED_COLUMNS)) {
$parts[] = [$this->group];
} else {
$parts[] = "{$this->delimitedTable}.*";
}
return $this->getConditionHash(json_encode($parts), array_merge(
$this->parameters['select'],

This comment has been minimized.

Copy link
@Majkl578

Majkl578 May 7, 2016

Contributor

Why not variadic unpacking?

This comment has been minimized.

Copy link
@norbe

norbe May 12, 2016

Author Contributor

Becouse of "Cannot unpack array with string keys"...

This comment has been minimized.

Copy link
@norbe

norbe May 12, 2016

Author Contributor

Should I fix it to use call_user_func_array again or add array_values?

$this->parameters['joinCondition'] ? call_user_func_array('array_merge', $this->parameters['joinCondition']) : [],
$this->parameters['where'],
$this->parameters['group'],
$this->parameters['having'],
$this->parameters['order']
));
}


/**
* Returns SQL query.
* @param string list of columns
Expand Down

0 comments on commit e5a9b9e

Please sign in to comment.