()
| 15771 | let previousSlug = null; |
| 15772 | if (selectedWifiInterface) { |
| 15773 | const prevMeta = Array.isArray(previousList) |
| 15774 | ? previousList.find(entry => entry && entry.name === selectedWifiInterface) |
| 15775 | : null; |
| 15776 | if (prevMeta) { |
| 15777 | previousSlug = prevMeta.network_slug || (prevMeta.connected_ssid ? slugifyNetworkIdentifier(prevMeta.connected_ssid) : null); |
| 15778 | } |
| 15779 | } |
| 15780 | |
| 15781 | wifiInterfaceMetadata = entries ? normalizeInterfaceMetadata(entries) : []; |
| 15782 | |
| 15783 | if (selectedWifiInterface) { |
| 15784 | const nextMeta = wifiInterfaceMetadata.find(entry => entry && entry.name === selectedWifiInterface); |
| 15785 | const nextSlug = nextMeta ? (nextMeta.network_slug || (nextMeta.connected_ssid ? slugifyNetworkIdentifier(nextMeta.connected_ssid) : null)) : null; |
| 15786 | if (previousSlug !== nextSlug) { |
| 15787 | clearDashboardStatsCache(); |
| 15788 | refreshDashboardStatsForCurrentSelection({ forceRefresh: true }).catch(err => { |
| 15789 | console.debug('Dashboard stats refresh failed after interface metadata update', err); |
| 15790 | }); |
| 15791 | } |
| 15792 | } |
| 15793 | } |
| 15794 | |
| 15795 | function clearDashboardStatsCache() { |
| 15796 | dashboardStatsCache = { key: null, timestamp: 0, data: null }; |
| 15797 | } |
| 15798 | |
| 15799 | async function fetchDashboardStatsForSelection(options = {}) { |
| 15800 | const { forceRefresh = false } = options; |
| 15801 | const { network } = getSelectedDashboardNetworkKey(); |
| 15802 | const cacheKey = network ? `network:${network}` : 'network:global'; |
| 15803 | const now = Date.now(); |
| 15804 | |
| 15805 | const cached = dashboardStatsCache; |
| 15806 | if (!forceRefresh && cached.key === cacheKey && (now - cached.timestamp) < DASHBOARD_STATS_CACHE_TTL && cached.data) { |
| 15807 | return cached.data; |
| 15808 | } |
| 15809 | |
| 15810 | if (!forceRefresh && dashboardStatsRequestState && dashboardStatsRequestState.key === cacheKey) { |
| 15811 | return dashboardStatsRequestState.promise; |
| 15812 | } |
| 15813 | |
| 15814 | const query = network ? `/api/dashboard/stats?network=${encodeURIComponent(network)}` : '/api/dashboard/stats'; |
| 15815 | const requestPromise = (async () => { |
| 15816 | try { |
| 15817 | const payload = await fetchAPI(query); |
| 15818 | dashboardStatsCache = { key: cacheKey, timestamp: Date.now(), data: payload }; |
| 15819 | return payload; |
| 15820 | } finally { |
| 15821 | if (dashboardStatsRequestState && dashboardStatsRequestState.key === cacheKey) { |
| 15822 | dashboardStatsRequestState = null; |
| 15823 | } |
| 15824 | } |
| 15825 | })(); |
| 15826 | |
| 15827 | dashboardStatsRequestState = { key: cacheKey, promise: requestPromise }; |
| 15828 | return requestPromise; |
| 15829 | } |
| 15830 |
no test coverage detected