Fixed error cache build link VC
This commit is contained in:
parent
6ccc606c74
commit
a55e431b46
|
@ -45,6 +45,21 @@ function createVisualConsole(
|
|||
visualConsoleId,
|
||||
function(error, data) {
|
||||
if (error) {
|
||||
//Remove spinner change VC.
|
||||
document
|
||||
.getElementById("visual-console-container")
|
||||
.classList.remove("is-updating");
|
||||
|
||||
var div = document
|
||||
.getElementById("visual-console-container")
|
||||
.querySelector(".div-visual-console-spinner");
|
||||
|
||||
if (div !== null) {
|
||||
var parent = div.parentElement;
|
||||
if (parent !== null) {
|
||||
parent.removeChild(div);
|
||||
}
|
||||
}
|
||||
console.log(
|
||||
"[ERROR]",
|
||||
"[VISUAL-CONSOLE-CLIENT]",
|
||||
|
|
|
@ -75,39 +75,26 @@ abstract class CachedModel extends Model
|
|||
public static function fromDB(array $filter): Model
|
||||
{
|
||||
global $config;
|
||||
|
||||
// TODO: Remove references to the VC items. This class should be usable with any resource.
|
||||
$save_cache = false;
|
||||
if ($filter['cache_expiration'] > 0) {
|
||||
// Obtain the item's data from cache.
|
||||
$cachedData = static::fetchCachedData($filter);
|
||||
if ($cachedData === null) {
|
||||
$userId = (static::$indexCacheByUser === true) ? $config['id_user'] : null;
|
||||
$data = static::fetchCachedData($filter);
|
||||
$save_cache = true;
|
||||
}
|
||||
|
||||
// Delete expired data cache.
|
||||
static::clearCachedData(
|
||||
[
|
||||
'vc_item_id' => $filter['id'],
|
||||
'vc_id' => $filter['id_layout'],
|
||||
'user_id' => $userId,
|
||||
]
|
||||
);
|
||||
// Obtain the item's data from the database.
|
||||
$data = static::fetchDataFromDB($filter);
|
||||
// Save the item's data in cache.
|
||||
static::saveCachedData(
|
||||
[
|
||||
'vc_item_id' => $filter['id'],
|
||||
'vc_id' => $filter['id_layout'],
|
||||
'user_id' => $userId,
|
||||
'expiration' => $filter['cache_expiration'],
|
||||
],
|
||||
$data
|
||||
);
|
||||
} else {
|
||||
$data = $cachedData;
|
||||
}
|
||||
} else {
|
||||
if (isset($data) === false) {
|
||||
$data = static::fetchDataFromDB($filter);
|
||||
} else {
|
||||
// Retrieved from cache.
|
||||
$save_cache = false;
|
||||
}
|
||||
|
||||
if ($save_cache === true) {
|
||||
// Rebuild cache.
|
||||
if (static::saveCachedData($filter, $data) !== true) {
|
||||
throw new \Exception(
|
||||
$config['dbconnection']->error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return static::fromArray($data);
|
||||
|
|
|
@ -413,7 +413,7 @@ final class Container extends Model
|
|||
try {
|
||||
array_push($items, $class::fromDB($data));
|
||||
} catch (\Throwable $e) {
|
||||
// TODO: Log this?
|
||||
error_log('VC[Container]: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,13 @@ class Item extends CachedModel
|
|||
*/
|
||||
protected static $useHtmlOutput = false;
|
||||
|
||||
/**
|
||||
* Enable the cache index by user id.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $indexCacheByUser = true;
|
||||
|
||||
|
||||
/**
|
||||
* Validate the received data structure to ensure if we can extract the
|
||||
|
@ -815,6 +822,14 @@ class Item extends CachedModel
|
|||
);
|
||||
|
||||
if ($data === false) {
|
||||
// Invalid entry, clean it.
|
||||
self::clearCachedData(
|
||||
[
|
||||
'vc_id' => $filter['vc_id'],
|
||||
'vc_item_id' => $filter['vc_item_id'],
|
||||
'user_id' => $filter['user_id'],
|
||||
]
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -835,14 +850,19 @@ class Item extends CachedModel
|
|||
*/
|
||||
protected static function saveCachedData(array $filter, array $data): bool
|
||||
{
|
||||
global $config;
|
||||
if (static::$indexCacheByUser === true) {
|
||||
$filter['user_id'] = $config['id_user'];
|
||||
}
|
||||
|
||||
return \db_process_sql_insert(
|
||||
'tvisual_console_elements_cache',
|
||||
[
|
||||
'vc_id' => $filter['vc_id'],
|
||||
'vc_item_id' => $filter['vc_item_id'],
|
||||
'vc_id' => $data['id_layout'],
|
||||
'vc_item_id' => $data['id'],
|
||||
'user_id' => $filter['user_id'],
|
||||
'data' => base64_encode(json_encode($data)),
|
||||
'expiration' => $filter['expiration'],
|
||||
'expiration' => $data['cache_expiration'],
|
||||
]
|
||||
) > 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue