mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-21 00:02:18 +02:00
Merge pull request #2460 from Nicofuma/ticket/11224
[ticket/11224] SQL cache destroy does not destroy queries to tables joined
This commit is contained in:
commit
d264369441
16
phpBB/phpbb/cache/driver/memory.php
vendored
16
phpBB/phpbb/cache/driver/memory.php
vendored
@ -208,12 +208,24 @@ abstract class memory extends \phpbb\cache\driver\base
|
||||
// determine which tables this query belongs to
|
||||
// Some queries use backticks, namely the get_database_size() query
|
||||
// don't check for conformity, the SQL would error and not reach here.
|
||||
if (!preg_match('/FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?/', $query, $regs))
|
||||
if (!preg_match_all('/(?:FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?)|(?:JOIN (`?\\w+`?(?: \\w+)?))/', $query, $regs, PREG_SET_ORDER))
|
||||
{
|
||||
// Bail out if the match fails.
|
||||
return $query_result;
|
||||
}
|
||||
$tables = array_map('trim', explode(',', $regs[1]));
|
||||
|
||||
$tables = array();
|
||||
foreach ($regs as $match)
|
||||
{
|
||||
if ($match[0][0] == 'F')
|
||||
{
|
||||
$tables = array_merge($tables, array_map('trim', explode(',', $match[1])));
|
||||
}
|
||||
else
|
||||
{
|
||||
$tables[] = $match[2];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($tables as $table_name)
|
||||
{
|
||||
|
62
tests/cache/cache_memory.php
vendored
Normal file
62
tests/cache/cache_memory.php
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/acm/acm_memory.php';
|
||||
|
||||
class phpbb_cache_memory extends acm_memory
|
||||
{
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* Set cache path
|
||||
*/
|
||||
function phpbb_cache_memory()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
{
|
||||
return $this->data[$var];
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
{
|
||||
$this->data[$var] = $data;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
{
|
||||
unset($this->data[$var]);
|
||||
return true;
|
||||
}
|
||||
}
|
125
tests/cache/cache_memory_test.php
vendored
Normal file
125
tests/cache/cache_memory_test.php
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/cache_memory.php';
|
||||
|
||||
class phpbb_cache_memory_test extends phpbb_database_test_case
|
||||
{
|
||||
protected $cache;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/cache_memory.xml');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
global $db;
|
||||
parent::setUp();
|
||||
|
||||
$this->cache = new phpbb_cache_memory();
|
||||
$db = $this->new_dbal();
|
||||
}
|
||||
|
||||
static public function cache_single_query_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'SELECT * FROM ' . POSTS_TABLE,
|
||||
3,
|
||||
),
|
||||
),
|
||||
POSTS_TABLE,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'SELECT * FROM ' . POSTS_TABLE,
|
||||
3,
|
||||
),
|
||||
array(
|
||||
'SELECT * FROM ' . POSTS_TABLE . ' p
|
||||
LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
|
||||
3,
|
||||
),
|
||||
),
|
||||
POSTS_TABLE,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'SELECT * FROM ' . POSTS_TABLE,
|
||||
3,
|
||||
),
|
||||
array(
|
||||
'SELECT * FROM ' . POSTS_TABLE . ' p
|
||||
LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
|
||||
3,
|
||||
),
|
||||
array(
|
||||
'SELECT * FROM ' . POSTS_TABLE . ' p
|
||||
LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id
|
||||
LEFT JOIN ' . USERS_TABLE . ' u ON p.poster_id = u.user_id',
|
||||
3,
|
||||
),
|
||||
),
|
||||
POSTS_TABLE,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'SELECT * FROM ' . POSTS_TABLE . ' p
|
||||
LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id',
|
||||
3,
|
||||
),
|
||||
array(
|
||||
'SELECT * FROM ' . POSTS_TABLE . ' p
|
||||
LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id
|
||||
LEFT JOIN ' . USERS_TABLE . ' u ON p.poster_id = u.user_id',
|
||||
3,
|
||||
),
|
||||
),
|
||||
TOPICS_TABLE,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider cache_single_query_data
|
||||
*/
|
||||
public function test_cache_single_query($sql_queries, $table)
|
||||
{
|
||||
global $db;
|
||||
|
||||
foreach ($sql_queries as $query)
|
||||
{
|
||||
$sql_request_res = $db->sql_query($query[0]);
|
||||
|
||||
$this->cache->sql_save($query[0], $sql_request_res, 1);
|
||||
|
||||
$results = array();
|
||||
$query_id = $this->cache->sql_load($query[0]);
|
||||
while ($row = $this->cache->sql_fetchrow($query_id))
|
||||
{
|
||||
$results[] = $row;
|
||||
}
|
||||
$this->cache->sql_freeresult($query_id);
|
||||
$this->assertEquals($query[1], sizeof($results));
|
||||
}
|
||||
|
||||
$this->cache->destroy('sql', $table);
|
||||
|
||||
foreach ($sql_queries as $query)
|
||||
{
|
||||
$this->assertNotEquals(false, $this->cache->sql_load($query[0]));
|
||||
}
|
||||
}
|
||||
}
|
85
tests/cache/fixtures/cache_memory.xml
vendored
Normal file
85
tests/cache/fixtures/cache_memory.xml
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_topics">
|
||||
<column>topic_id</column>
|
||||
<column>forum_id</column>
|
||||
<column>topic_title</column>
|
||||
<column>topic_first_post_id</column>
|
||||
<column>topic_last_post_id</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>Topic</value>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_posts">
|
||||
<column>post_id</column>
|
||||
<column>poster_id</column>
|
||||
<column>topic_id</column>
|
||||
<column>forum_id</column>
|
||||
<column>post_text</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>Post 1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>Post 2</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>3</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>Post 3</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_users">
|
||||
<column>user_id</column>
|
||||
<column>user_posts</column>
|
||||
<column>username</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<column>user_occ</column>
|
||||
<column>user_interests</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>user 1</value>
|
||||
<value>user 1</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>user 2</value>
|
||||
<value>user 2</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>1</value>
|
||||
<value>user 3</value>
|
||||
<value>user 3</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
Loading…
x
Reference in New Issue
Block a user