mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 00:04:37 +02:00
Now only the Group item of the VC is cached by user
This commit is contained in:
parent
fb8bc48d64
commit
5ea79cdfb8
@ -12,6 +12,13 @@ use Models\Model;
|
||||
abstract class CachedModel extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to decide if the cache should also be indexed by user or not.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $indexCacheByUser = false;
|
||||
|
||||
|
||||
/**
|
||||
* Obtain a data structure from the database using a filter.
|
||||
@ -73,12 +80,14 @@ abstract class CachedModel extends Model
|
||||
// Obtain the item's data from cache.
|
||||
$cachedData = static::fetchCachedData($filter);
|
||||
if ($cachedData === null) {
|
||||
$userId = (static::$indexCacheByUser === true) ? $config['id_user'] : null;
|
||||
|
||||
// Delete expired data cache.
|
||||
static::clearCachedData(
|
||||
[
|
||||
'vc_item_id' => $filter['id'],
|
||||
'vc_id' => $filter['id_layout'],
|
||||
'user_id' => $config['id_user'],
|
||||
'user_id' => $userId,
|
||||
]
|
||||
);
|
||||
// Obtain the item's data from the database.
|
||||
@ -88,7 +97,7 @@ abstract class CachedModel extends Model
|
||||
[
|
||||
'vc_item_id' => $filter['id'],
|
||||
'vc_id' => $filter['id_layout'],
|
||||
'user_id' => $config['id_user'],
|
||||
'user_id' => $userId,
|
||||
'expiration' => $filter['cache_expiration'],
|
||||
],
|
||||
$data
|
||||
|
@ -735,18 +735,21 @@ class Item extends CachedModel
|
||||
{
|
||||
global $config;
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT `data`
|
||||
FROM `tvisual_console_elements_cache`
|
||||
WHERE `vc_item_id` = %d
|
||||
AND `vc_id` = %d
|
||||
AND `user_id` LIKE \'%s\'
|
||||
AND (UNIX_TIMESTAMP(`created_at`) + `expiration`) > UNIX_TIMESTAMP()',
|
||||
$filter['id'],
|
||||
$filter['id_layout'],
|
||||
$config['id_user']
|
||||
$filter = [
|
||||
'vc_id' => (int) $filter['id_layout'],
|
||||
'vc_item_id' => (int) $filter['id'],
|
||||
'(UNIX_TIMESTAMP(`created_at`) + `expiration`) > UNIX_TIMESTAMP()'
|
||||
];
|
||||
|
||||
if (static::$indexCacheByUser === true) {
|
||||
$filter['user_id'] = $config['id_user'];
|
||||
}
|
||||
|
||||
$data = \db_get_value_filter(
|
||||
'data',
|
||||
'tvisual_console_elements_cache',
|
||||
$filter
|
||||
);
|
||||
$data = \db_get_value_sql($sql);
|
||||
|
||||
if ($data === false) {
|
||||
return null;
|
||||
|
@ -26,6 +26,13 @@ final class Group extends Item
|
||||
*/
|
||||
protected static $useHtmlOutput = true;
|
||||
|
||||
/**
|
||||
* Enable the cache index by user id.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $indexCacheByUser = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
|
Loading…
x
Reference in New Issue
Block a user