From d9c263d5062d3076d31d5e09c3d8d6c08870f911 Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Sat, 28 Feb 2026 00:13:22 +0000 Subject: [PATCH] feat: Update cache handling to normalize legacy device data format and improve logging --- front/js/cache.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/front/js/cache.js b/front/js/cache.js index 84ce9b6e..fabc8c56 100644 --- a/front/js/cache.js +++ b/front/js/cache.js @@ -109,7 +109,7 @@ function parseDeviceCache(cachedStr) { // If result is an object with a .data property, extract it (handles legacy format) if (parsed && typeof parsed === 'object' && !Array.isArray(parsed) && Array.isArray(parsed.data)) { - console.warn('[parseDeviceCache] Extracting .data property from wrapper object'); + console.debug('[parseDeviceCache] Extracting .data property from wrapper object'); parsed = parsed.data; } @@ -505,6 +505,18 @@ function cacheDevices() return new Promise((resolve, reject) => { if(getCache(CACHE_KEYS.initFlag('cacheDevices')) === "true") { + // One-time migration: normalize legacy { data: [...] } wrapper to a plain array. + // Old cache entries from prior versions stored the raw API envelope; re-write + // them in the flat format so parseDeviceCache never needs the fallback branch. + const raw = getCache(CACHE_KEYS.DEVICES_ALL); + if (raw) { + try { + const p = JSON.parse(raw); + if (p && typeof p === 'object' && !Array.isArray(p) && Array.isArray(p.data)) { + setCache(CACHE_KEYS.DEVICES_ALL, JSON.stringify(p.data)); + } + } catch (e) { /* ignore malformed cache – will be refreshed next init */ } + } resolve(); return; }