From a2aeb110cbcfcc80f274a25a54a26dda81df0f09 Mon Sep 17 00:00:00 2001 From: sn0w12 Date: Sat, 24 Aug 2024 20:40:03 +0200 Subject: [PATCH] Update logging, remove settings cache. --- web/js/loggingLevel.js | 4 +++- web/js/sn0w.js | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/web/js/loggingLevel.js b/web/js/loggingLevel.js index adb2026..f130dbb 100644 --- a/web/js/loggingLevel.js +++ b/web/js/loggingLevel.js @@ -21,7 +21,9 @@ async function updateLoggingLevel() { await api.fetchApi(`${SettingUtils.API_PREFIX}/update_logging_level`, { method: 'GET', }); - SettingUtils.logSn0w("Logging Levels Updated", "debug", "setting", `Logging levels selected:\n${loggingArray}`) + + SettingUtils.setLoggingLevel(loggingArray); + SettingUtils.logSn0w("Logging Levels Updated", "debug", "setting", `Logging levels selected:\n${loggingArray}`); } const debouncedUpdateLoggingLevel = SettingUtils.debounce(updateLoggingLevel, 1000); diff --git a/web/js/sn0w.js b/web/js/sn0w.js index f6f42cc..ea58567 100644 --- a/web/js/sn0w.js +++ b/web/js/sn0w.js @@ -4,17 +4,9 @@ import { $el } from '../../../scripts/ui.js' export class SettingUtils { static API_PREFIX = '/sn0w'; - static settingsCache = {}; + static cachedLoggingLevel = null; static async getSetting(url, defaultValue = null) { - const currentTime = Date.now(); - const cacheEntry = this.settingsCache[url]; - - // Check if the cache entry exists and is still valid (not older than 1 seconds) - if (cacheEntry && currentTime - cacheEntry.timestamp < 1000) { - return cacheEntry.data; - } - try { const settingUrl = `/settings/${url}`; const response = await fetch(settingUrl); @@ -464,7 +456,7 @@ export class SettingUtils { entry.style.alignItems = 'center'; } }; - let arr = [] + let starred = [0, []]; menuEntries.forEach((entry) => { const value = entry.getAttribute('data-value'); @@ -496,8 +488,8 @@ export class SettingUtils { const currentBgColor = window.getComputedStyle(entry).backgroundColor; checkAndUpdateBackgroundColor(entry, currentBgColor); } - SettingUtils.logSn0w(`Total Favourited Items: ${starred[0]}`, "debug", "node", starred[1]) }); + SettingUtils.logSn0w(`Total Favourited Items: ${starred[0]}`, "debug", "node", starred[1]) } static observeContextMenu(existingList) { @@ -559,8 +551,15 @@ export class SettingUtils { }; } + static setLoggingLevel(loggingLevel) { + this.cachedLoggingLevel = loggingLevel; + } + static async logSn0w(message, type, category = "", detailMessage = "") { - const loggingLevels = await SettingUtils.getSetting("sn0w.LoggingLevel"); + let loggingLevels = this.cachedLoggingLevel; + if (loggingLevels == null) { + loggingLevels = await SettingUtils.getSetting("sn0w.LoggingLevel"); + } const alwaysLog = ["emergency", "alert", "critical", "error"] const logLevel = type.toLowerCase();