diff --git a/doc/02-Installation.md b/doc/02-Installation.md index d7a5f224..a358a146 100644 --- a/doc/02-Installation.md +++ b/doc/02-Installation.md @@ -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 ----------------------- diff --git a/library/Director/Db.php b/library/Director/Db.php index c8aa9cfd..abfc7cfd 100644 --- a/library/Director/Db.php +++ b/library/Director/Db.php @@ -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()) { diff --git a/library/Director/Db/Cache/CustomVariableCache.php b/library/Director/Db/Cache/CustomVariableCache.php index c430b472..517a1bfd 100644 --- a/library/Director/Db/Cache/CustomVariableCache.php +++ b/library/Director/Db/Cache/CustomVariableCache.php @@ -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 {