mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/11037] Eliminate global $db usage in cache drivers.
The only time $db is needed in cache drivers is to navigate the result set in sql_save. Pass it as a parameter in that function. PHPBB3-11037
This commit is contained in:
parent
3701d83ecb
commit
e50f69187f
14 changed files with 22 additions and 21 deletions
6
phpBB/includes/cache/driver/file.php
vendored
6
phpBB/includes/cache/driver/file.php
vendored
|
@ -367,12 +367,10 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save sql query
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
function sql_save($query, $query_result, $ttl)
|
function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
|
||||||
{
|
{
|
||||||
global $db;
|
|
||||||
|
|
||||||
// Remove extra spaces and tabs
|
// Remove extra spaces and tabs
|
||||||
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
||||||
|
|
||||||
|
|
3
phpBB/includes/cache/driver/interface.php
vendored
3
phpBB/includes/cache/driver/interface.php
vendored
|
@ -85,6 +85,7 @@ interface phpbb_cache_driver_interface
|
||||||
* result to persistent storage. In other words, there is no need
|
* result to persistent storage. In other words, there is no need
|
||||||
* to call save() afterwards.
|
* to call save() afterwards.
|
||||||
*
|
*
|
||||||
|
* @param phpbb_db_driver $db Database connection
|
||||||
* @param string $query SQL query, should be used for generating storage key
|
* @param string $query SQL query, should be used for generating storage key
|
||||||
* @param mixed $query_result The result from dbal::sql_query, to be passed to
|
* @param mixed $query_result The result from dbal::sql_query, to be passed to
|
||||||
* dbal::sql_fetchrow to get all rows and store them
|
* dbal::sql_fetchrow to get all rows and store them
|
||||||
|
@ -95,7 +96,7 @@ interface phpbb_cache_driver_interface
|
||||||
* representing the query should be returned. Otherwise
|
* representing the query should be returned. Otherwise
|
||||||
* the original $query_result should be returned.
|
* the original $query_result should be returned.
|
||||||
*/
|
*/
|
||||||
public function sql_save($query, $query_result, $ttl);
|
public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if result for a given SQL query exists in cache.
|
* Check if result for a given SQL query exists in cache.
|
||||||
|
|
6
phpBB/includes/cache/driver/memory.php
vendored
6
phpBB/includes/cache/driver/memory.php
vendored
|
@ -283,12 +283,10 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save sql query
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
function sql_save($query, $query_result, $ttl)
|
function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
|
||||||
{
|
{
|
||||||
global $db;
|
|
||||||
|
|
||||||
// Remove extra spaces and tabs
|
// Remove extra spaces and tabs
|
||||||
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
||||||
$hash = md5($query);
|
$hash = md5($query);
|
||||||
|
|
4
phpBB/includes/cache/driver/null.php
vendored
4
phpBB/includes/cache/driver/null.php
vendored
|
@ -105,9 +105,9 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save sql query
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
function sql_save($query, $query_result, $ttl)
|
function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
|
||||||
{
|
{
|
||||||
return $query_result;
|
return $query_result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,7 +270,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver
|
||||||
if ($cache_ttl)
|
if ($cache_ttl)
|
||||||
{
|
{
|
||||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||||
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
|
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||||
}
|
}
|
||||||
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -168,7 +168,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver
|
||||||
if ($cache_ttl)
|
if ($cache_ttl)
|
||||||
{
|
{
|
||||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||||
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
|
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||||
}
|
}
|
||||||
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -197,7 +197,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver
|
||||||
if ($cache_ttl)
|
if ($cache_ttl)
|
||||||
{
|
{
|
||||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||||
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
|
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||||
}
|
}
|
||||||
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -337,7 +337,7 @@ class phpbb_db_driver_mssqlnative extends phpbb_db_driver
|
||||||
if ($cache_ttl)
|
if ($cache_ttl)
|
||||||
{
|
{
|
||||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||||
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
|
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||||
}
|
}
|
||||||
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -206,7 +206,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver
|
||||||
if ($cache_ttl)
|
if ($cache_ttl)
|
||||||
{
|
{
|
||||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||||
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
|
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||||
}
|
}
|
||||||
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -201,7 +201,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver
|
||||||
|
|
||||||
if ($cache_ttl)
|
if ($cache_ttl)
|
||||||
{
|
{
|
||||||
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
|
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (defined('DEBUG'))
|
else if (defined('DEBUG'))
|
||||||
|
|
|
@ -446,7 +446,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver
|
||||||
if ($cache_ttl)
|
if ($cache_ttl)
|
||||||
{
|
{
|
||||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||||
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
|
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||||
}
|
}
|
||||||
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -211,7 +211,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver
|
||||||
if ($cache_ttl)
|
if ($cache_ttl)
|
||||||
{
|
{
|
||||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||||
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
|
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||||
}
|
}
|
||||||
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -152,7 +152,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver
|
||||||
if ($cache_ttl)
|
if ($cache_ttl)
|
||||||
{
|
{
|
||||||
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
||||||
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
|
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
|
||||||
}
|
}
|
||||||
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -121,7 +121,11 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface
|
||||||
public function sql_load($query)
|
public function sql_load($query)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public function sql_save($query, $query_result, $ttl)
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
|
||||||
{
|
{
|
||||||
return $query_result;
|
return $query_result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue