mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-09-29 20:59:01 +02:00
ENHANCEMENT: constraint queries are now cached
This commit is contained in:
parent
a59e02efee
commit
f3e29be23c
@ -63,6 +63,16 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
*/
|
*/
|
||||||
public static $check_database_exists = true;
|
public static $check_database_exists = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This holds a copy of all the constraint results that are returned
|
||||||
|
* via the function constraintExists(). This is a bit faster than
|
||||||
|
* repeatedly querying this column, and should allow the database
|
||||||
|
* to use it's built-in caching features for better queries.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $cached_constraints=array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to a PostgreSQL database.
|
* Connect to a PostgreSQL database.
|
||||||
* @param array $parameters An map of parameters, which should include:
|
* @param array $parameters An map of parameters, which should include:
|
||||||
@ -887,12 +897,20 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find out what the constraint information is, given a constraint name.
|
||||||
|
* We also cache this result, so the next time we don't need to do a
|
||||||
|
* query all over again.
|
||||||
|
*
|
||||||
|
* @param string $constraint
|
||||||
|
*/
|
||||||
function constraintExists($constraint){
|
function constraintExists($constraint){
|
||||||
|
if(!isset(self::$cached_constraints[$constraint])){
|
||||||
$exists=DB::query("SELECT conname,pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE r.contype = 'c' AND conname='$constraint' ORDER BY 1;")->first();
|
$exists=DB::query("SELECT conname,pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE r.contype = 'c' AND conname='$constraint' ORDER BY 1;")->first();
|
||||||
|
self::$cached_constraints[$constraint]=$exists;
|
||||||
|
}
|
||||||
|
|
||||||
//echo "SELECT conname,pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE r.contype = 'c' AND conname='$constraint' ORDER BY 1;<Br>";
|
return self::$cached_constraints[$constraint];
|
||||||
|
|
||||||
return $exists;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user