CustomVariableCache: optionally use digest()...

...for PostgreSQL in case pgcrypto is installed. Also add related hint to the
installation documentation
This commit is contained in:
Thomas Gelf 2016-10-09 12:43:04 +00:00
parent 6f12663756
commit 1bc4a397a8
3 changed files with 25 additions and 2 deletions

View File

@ -35,8 +35,12 @@ command.
psql -q -c "CREATE DATABASE director WITH ENCODING 'UTF8';"
psql director -q -c "CREATE USER director WITH PASSWORD 'some-password';
GRANT ALL PRIVILEGES ON DATABASE director TO director;"
GRANT ALL PRIVILEGES ON DATABASE director TO director;
CREATE EXTENSION pgcrypto;"
Hint: pgcrypto helps to boost performance, but is currently optional. In case you
do not have it available on your platform and/or do not know how to solve this
just leave away the 'CREATE EXTENSION' part.
Web-based Configuration
-----------------------

View File

@ -632,6 +632,17 @@ class Db extends DbConnection
return $this->getDbType() === 'pgsql';
}
public function hasPgExtension($name)
{
$db = $this->db();
$query = $db->select()->from(
array('e' => 'pg_extension'),
array('cnt' => 'COUNT(*)')
)->where('extname = ?', $name);
return (int) $db->fetchOne($query) === 1;
}
public function dbHexFunc($column)
{
if ($this->isPgsql()) {

View File

@ -27,7 +27,11 @@ class CustomVariableCache
'checksum' => '(NULL)',
);
if (! $connection->isPgsql()) {
if ($connection->isPgsql()) {
if ($connection->hasPgExtension('pgcrypto')) {
$columns['checksum'] = "DIGEST(v.varvalue || ';' || v.format, 'sha1')";
}
} else {
$columns['checksum'] = "UNHEX(SHA1(v.varvalue || ';' || v.format))";
}
@ -41,6 +45,10 @@ class CustomVariableCache
$id = $row->id;
unset($row->id);
if (is_resource($row->checksum)) {
$row->checksum = stream_get_contents($row->checksum);
}
if (array_key_exists($id, $this->rowsById)) {
$this->rowsById[$id][] = $row;
} else {