mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-04 17:21:23 -07:00
work on stale cache #1554
This commit is contained in:
@@ -299,7 +299,7 @@ function updateChevrons(currentMac) {
|
|||||||
|
|
||||||
showSpinner();
|
showSpinner();
|
||||||
|
|
||||||
cacheDevices().then(() => {
|
cacheDevices(true).then(() => {
|
||||||
hideSpinner();
|
hideSpinner();
|
||||||
|
|
||||||
// Retry after re-caching
|
// Retry after re-caching
|
||||||
@@ -507,7 +507,7 @@ function updateDevicePageName(mac) {
|
|||||||
if (mac != 'new' && (name === null|| owner === null)) {
|
if (mac != 'new' && (name === null|| owner === null)) {
|
||||||
console.warn("Device not found in cache, retrying after re-cache:", mac);
|
console.warn("Device not found in cache, retrying after re-cache:", mac);
|
||||||
showSpinner();
|
showSpinner();
|
||||||
cacheDevices().then(() => {
|
cacheDevices(true).then(() => {
|
||||||
hideSpinner();
|
hideSpinner();
|
||||||
// Retry after successful cache
|
// Retry after successful cache
|
||||||
updateDevicePageName(mac);
|
updateDevicePageName(mac);
|
||||||
|
|||||||
@@ -451,11 +451,23 @@ function getDevDataByMac(macAddress, dbColumn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Cache the devices as one JSON
|
/**
|
||||||
function cacheDevices()
|
* Fetches the full device list from table_devices.json and stores it in
|
||||||
|
* localStorage under CACHE_KEYS.DEVICES_ALL.
|
||||||
|
*
|
||||||
|
* On subsequent calls the fetch is skipped if the initFlag is already set,
|
||||||
|
* unless forceRefresh is true. Pass forceRefresh = true whenever the caller
|
||||||
|
* knows the cached list may be stale (e.g. a device was not found by MAC and
|
||||||
|
* the page needs to recover without a full clearCache()).
|
||||||
|
*
|
||||||
|
* @param {boolean} [forceRefresh=false] - When true, bypasses the initFlag
|
||||||
|
* guard and always fetches fresh data from the server.
|
||||||
|
* @returns {Promise<void>} Resolves when the cache has been populated.
|
||||||
|
*/
|
||||||
|
function cacheDevices(forceRefresh = false)
|
||||||
{
|
{
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if(getCache(CACHE_KEYS.initFlag('cacheDevices')) === "true")
|
if(!forceRefresh && getCache(CACHE_KEYS.initFlag('cacheDevices')) === "true")
|
||||||
{
|
{
|
||||||
// One-time migration: normalize legacy { data: [...] } wrapper to a plain array.
|
// One-time migration: normalize legacy { data: [...] } wrapper to a plain array.
|
||||||
// Old cache entries from prior versions stored the raw API envelope; re-write
|
// Old cache entries from prior versions stored the raw API envelope; re-write
|
||||||
|
|||||||
Reference in New Issue
Block a user