1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-21 16:22:22 +02:00

Merge pull request #932 from EXreaction/ticket/10875

Ticket/10875
This commit is contained in:
Nils Adermann 2012-08-14 02:30:49 -07:00
commit dca9057559
18 changed files with 103 additions and 42 deletions

View File

@ -364,7 +364,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
/**
* Save sql query
*/
function sql_save($query, &$query_result, $ttl)
function sql_save($query, $query_result, $ttl)
{
global $db;
@ -385,6 +385,8 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
{
$query_result = $query_id;
}
return $query_id;
}
/**

View File

@ -75,7 +75,7 @@ interface phpbb_cache_driver_interface
/**
* Save sql query
*/
public function sql_save($query, &$query_result, $ttl);
public function sql_save($query, $query_result, $ttl);
/**
* Ceck if a given sql query exist in cache

View File

@ -280,7 +280,7 @@ class phpbb_cache_driver_memory extends phpbb_cache_driver_base
/**
* Save sql query
*/
function sql_save($query, &$query_result, $ttl)
function sql_save($query, $query_result, $ttl)
{
global $db;
@ -335,6 +335,8 @@ class phpbb_cache_driver_memory extends phpbb_cache_driver_base
$this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl);
$query_result = $query_id;
return $query_id;
}
/**

View File

@ -107,7 +107,7 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base
/**
* Save sql query
*/
function sql_save($query, &$query_result, $ttl)
function sql_save($query, $query_result, $ttl)
{
}

View File

@ -206,7 +206,7 @@ class dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@ -256,7 +256,7 @@ class dbal
$this->sql_rowseek($rownum, $query_id);
}
if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
if (!is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_fetchfield($query_id, $field);
}

View File

@ -272,7 +272,7 @@ class dbal_firebird extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$cache->sql_save($query, $this->query_result, $cache_ttl);
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@ -332,7 +332,7 @@ class dbal_firebird extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@ -398,7 +398,7 @@ class dbal_firebird extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}

View File

@ -162,7 +162,7 @@ class dbal_mssql extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$cache->sql_save($query, $this->query_result, $cache_ttl);
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@ -234,7 +234,7 @@ class dbal_mssql extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@ -271,7 +271,7 @@ class dbal_mssql extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@ -310,7 +310,7 @@ class dbal_mssql extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}

View File

@ -181,7 +181,7 @@ class dbal_mssql_odbc extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$cache->sql_save($query, $this->query_result, $cache_ttl);
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@ -254,7 +254,7 @@ class dbal_mssql_odbc extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@ -295,7 +295,7 @@ class dbal_mssql_odbc extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}

View File

@ -338,7 +338,7 @@ class dbal_mssqlnative extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$cache->sql_save($query, $this->query_result, $cache_ttl);
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@ -418,7 +418,7 @@ class dbal_mssqlnative extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@ -478,7 +478,7 @@ class dbal_mssqlnative extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}

View File

@ -190,7 +190,7 @@ class dbal_mysql extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$cache->sql_save($query, $this->query_result, $cache_ttl);
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@ -249,7 +249,7 @@ class dbal_mysql extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@ -270,7 +270,7 @@ class dbal_mysql extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@ -298,7 +298,7 @@ class dbal_mysql extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}

View File

@ -196,7 +196,7 @@ class dbal_mysqli extends dbal
if ($cache_ttl)
{
$cache->sql_save($query, $this->query_result, $cache_ttl);
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
}
else if (defined('DEBUG_EXTRA'))
@ -251,7 +251,7 @@ class dbal_mysqli extends dbal
$query_id = $this->query_result;
}
if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
if (!is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@ -278,7 +278,7 @@ class dbal_mysqli extends dbal
$query_id = $this->query_result;
}
if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
if (!is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@ -306,7 +306,7 @@ class dbal_mysqli extends dbal
$query_id = $this->query_result;
}
if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
if (!is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}

View File

@ -421,7 +421,7 @@ class dbal_oracle extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$cache->sql_save($query, $this->query_result, $cache_ttl);
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@ -473,7 +473,7 @@ class dbal_oracle extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@ -525,7 +525,7 @@ class dbal_oracle extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@ -594,7 +594,7 @@ class dbal_oracle extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}

View File

@ -218,7 +218,7 @@ class dbal_postgres extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$cache->sql_save($query, $this->query_result, $cache_ttl);
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@ -285,7 +285,7 @@ class dbal_postgres extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@ -306,7 +306,7 @@ class dbal_postgres extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@ -355,7 +355,7 @@ class dbal_postgres extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}

View File

@ -135,7 +135,7 @@ class dbal_sqlite extends dbal
if ($cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$cache->sql_save($query, $this->query_result, $cache_ttl);
$this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl);
}
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
{
@ -193,7 +193,7 @@ class dbal_sqlite extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
@ -214,7 +214,7 @@ class dbal_sqlite extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
@ -242,7 +242,7 @@ class dbal_sqlite extends dbal
$query_id = $this->query_result;
}
if (isset($cache->sql_rowset[$query_id]))
if ($cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}

View File

@ -349,7 +349,7 @@ class install_update extends module
// We are directly within an update. To make sure our update list is correct we check its status.
$update_list = ($request->variable('check_again', false, false, phpbb_request_interface::POST)) ? false : $cache->get('_update_list');
$modified = ($update_list !== false) ? @filemtime($cache->cache_dir . 'data_update_list.' . $phpEx) : 0;
$modified = ($update_list !== false) ? @filemtime($cache->get_driver()->cache_dir . 'data_update_list.' . $phpEx) : 0;
// Make sure the list is up-to-date
if ($update_list !== false)

View File

@ -9,7 +9,7 @@
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_cache_test extends phpbb_test_case
class phpbb_cache_test extends phpbb_database_test_case
{
private $cache_dir;
@ -18,8 +18,15 @@ class phpbb_cache_test extends phpbb_test_case
$this->cache_dir = dirname(__FILE__) . '/../tmp/cache/';
}
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
}
protected function setUp()
{
parent::setUp();
if (file_exists($this->cache_dir))
{
// cache directory possibly left after aborted
@ -35,6 +42,8 @@ class phpbb_cache_test extends phpbb_test_case
{
$this->remove_cache_dir();
}
parent::tearDown();
}
private function create_cache_dir()
@ -67,4 +76,34 @@ class phpbb_cache_test extends phpbb_test_case
'File ACM put and get'
);
}
public function test_cache_sql()
{
$driver = new phpbb_cache_driver_file($this->cache_dir);
global $db, $cache;
$db = $this->new_dbal();
$cache = new phpbb_cache_service($driver);
$sql = "SELECT * FROM phpbb_config
WHERE config_name = 'foo'";
$result = $db->sql_query($sql, 300);
$first_result = $db->sql_fetchrow($result);
$this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php');
$sql = "SELECT * FROM phpbb_config
WHERE config_name = 'foo'";
$result = $db->sql_query($sql, 300);
$this->assertEquals($first_result, $db->sql_fetchrow($result));
$sql = "SELECT * FROM phpbb_config
WHERE config_name = 'bar'";
$result = $db->sql_query($sql, 300);
$this->assertNotEquals($first_result, $db->sql_fetchrow($result));
$db->sql_close();
}
}

18
tests/cache/fixtures/config.xml vendored Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_config">
<column>config_name</column>
<column>config_value</column>
<column>is_dynamic</column>
<row>
<value>foo</value>
<value>23</value>
<value>0</value>
</row>
<row>
<value>bar</value>
<value>42</value>
<value>1</value>
</row>
</table>
</dataset>

View File

@ -121,7 +121,7 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface
public function sql_load($query)
{
}
public function sql_save($query, &$query_result, $ttl)
public function sql_save($query, $query_result, $ttl)
{
}
public function sql_exists($query_id)