mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
Remove implicit prepared statement cache and get the connection from the server container in \OC_DB
This commit is contained in:
parent
97a6f5c46b
commit
d4e929c37a
6 changed files with 13 additions and 62 deletions
|
|
@ -35,10 +35,6 @@ class Repair extends Command {
|
|||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||
// TODO: inject DB connection/factory when possible
|
||||
$connection = \OC_DB::getConnection();
|
||||
$connection->disableQueryStatementCaching();
|
||||
|
||||
$maintenanceMode = $this->config->getValue('maintenance', false);
|
||||
$this->config->setValue('maintenance', true);
|
||||
|
||||
|
|
|
|||
|
|
@ -110,10 +110,9 @@ class OC_DB {
|
|||
* The existing database connection is closed and connected again
|
||||
*/
|
||||
public static function reconnect() {
|
||||
if(self::$connection) {
|
||||
self::$connection->close();
|
||||
self::$connection->connect();
|
||||
}
|
||||
$connection = \OC::$server->getDatabaseConnection();
|
||||
$connection->close();
|
||||
$connection->connect();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -146,7 +145,7 @@ class OC_DB {
|
|||
* SQL query via Doctrine prepare(), needs to be execute()'d!
|
||||
*/
|
||||
static public function prepare( $query , $limit = null, $offset = null, $isManipulation = null) {
|
||||
self::connect();
|
||||
$connection = \OC::$server->getDatabaseConnection();
|
||||
|
||||
if ($isManipulation === null) {
|
||||
//try to guess, so we return the number of rows on manipulations
|
||||
|
|
@ -155,7 +154,7 @@ class OC_DB {
|
|||
|
||||
// return the result
|
||||
try {
|
||||
$result = self::$connection->prepare($query, $limit, $offset);
|
||||
$result =$connection->prepare($query, $limit, $offset);
|
||||
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||
throw new \DatabaseException($e->getMessage(), $query);
|
||||
}
|
||||
|
|
@ -252,8 +251,7 @@ class OC_DB {
|
|||
* cause trouble!
|
||||
*/
|
||||
public static function insertid($table=null) {
|
||||
self::connect();
|
||||
return self::$connection->lastInsertId($table);
|
||||
return \OC::$server->getDatabaseConnection()->lastInsertId($table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -263,24 +261,21 @@ class OC_DB {
|
|||
* @return boolean number of updated rows
|
||||
*/
|
||||
public static function insertIfNotExist($table, $input) {
|
||||
self::connect();
|
||||
return self::$connection->insertIfNotExist($table, $input);
|
||||
return \OC::$server->getDatabaseConnection()->insertIfNotExist($table, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a transaction
|
||||
*/
|
||||
public static function beginTransaction() {
|
||||
self::connect();
|
||||
self::$connection->beginTransaction();
|
||||
return \OC::$server->getDatabaseConnection()->beginTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the database changes done during a transaction that is in progress
|
||||
*/
|
||||
public static function commit() {
|
||||
self::connect();
|
||||
self::$connection->commit();
|
||||
return \OC::$server->getDatabaseConnection()->commit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -414,18 +409,6 @@ class OC_DB {
|
|||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
*/
|
||||
static public function enableCaching($enabled) {
|
||||
self::connect();
|
||||
if ($enabled) {
|
||||
self::$connection->enableQueryStatementCaching();
|
||||
} else {
|
||||
self::$connection->disableQueryStatementCaching();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a table exists in the database - the database prefix will be prepended
|
||||
*
|
||||
|
|
|
|||
|
|
@ -24,13 +24,6 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
|
|||
*/
|
||||
protected $adapter;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Driver\Statement[] $preparedQueries
|
||||
*/
|
||||
protected $preparedQueries = array();
|
||||
|
||||
protected $cachingQueryStatementEnabled = true;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the Connection class.
|
||||
*
|
||||
|
|
@ -70,9 +63,6 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
|
|||
$platform = $this->getDatabasePlatform();
|
||||
$statement = $platform->modifyLimitQuery($statement, $limit, $offset);
|
||||
} else {
|
||||
if (isset($this->preparedQueries[$statement]) && $this->cachingQueryStatementEnabled) {
|
||||
return $this->preparedQueries[$statement];
|
||||
}
|
||||
$origStatement = $statement;
|
||||
}
|
||||
$statement = $this->replaceTablePrefix($statement);
|
||||
|
|
@ -81,11 +71,7 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
|
|||
if(\OC_Config::getValue( 'log_query', false)) {
|
||||
\OC_Log::write('core', 'DB prepare : '.$statement, \OC_Log::DEBUG);
|
||||
}
|
||||
$result = parent::prepare($statement);
|
||||
if (is_null($limit) && $this->cachingQueryStatementEnabled) {
|
||||
$this->preparedQueries[$origStatement] = $result;
|
||||
}
|
||||
return $result;
|
||||
return parent::prepare($statement);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -98,19 +98,6 @@ class ConnectionFactory {
|
|||
new \Doctrine\DBAL\Configuration(),
|
||||
$eventManager
|
||||
);
|
||||
switch ($normalizedType) {
|
||||
case 'sqlite3':
|
||||
// Sqlite doesn't handle query caching and schema changes
|
||||
// TODO: find a better way to handle this
|
||||
/** @var $connection \OC\DB\Connection */
|
||||
$connection->disableQueryStatementCaching();
|
||||
break;
|
||||
case 'oci':
|
||||
// oracle seems to have issues with cached statements which have been closed
|
||||
/** @var $connection \OC\DB\Connection */
|
||||
$connection->disableQueryStatementCaching();
|
||||
break;
|
||||
}
|
||||
return $connection;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
namespace OC;
|
||||
|
||||
use \OC\DB\Connection;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -61,9 +61,9 @@ class Preferences {
|
|||
protected $cache = array();
|
||||
|
||||
/**
|
||||
* @param \OC\DB\Connection $conn
|
||||
* @param \OCP\IDBConnection $conn
|
||||
*/
|
||||
public function __construct(Connection $conn) {
|
||||
public function __construct(IDBConnection $conn) {
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,6 @@ class Updater extends BasicEmitter {
|
|||
* @return bool true if the operation succeeded, false otherwise
|
||||
*/
|
||||
public function upgrade() {
|
||||
\OC_DB::enableCaching(false);
|
||||
\OC_Config::setValue('maintenance', true);
|
||||
|
||||
$installedVersion = \OC_Config::getValue('version', '0.0.0');
|
||||
|
|
|
|||
Loading…
Reference in a new issue