MCPcopy Create free account
hub / github.com/Noumena-Network/code / refreshMetricsStatus

Function refreshMetricsStatus

src/services/api/metricsOptOut.ts:113–135  ·  view source on GitHub ↗

* Fetch (in-memory memoized) and persist to disk on change. * Errors are not persisted — a transient failure should not overwrite a * known-good disk value.

()

Source from the content-addressed store, hash-verified

111 * known-good disk value.
112 */
113async function refreshMetricsStatus(): Promise<MetricsStatus> {
114 const result = await memoizedCheckMetrics()
115 if (result.hasError) {
116 return result
117 }
118
119 const cached = getGlobalConfig().metricsStatusCache
120 const unchanged = cached !== undefined && cached.enabled === result.enabled
121 // Skip write when unchanged AND timestamp still fresh — avoids config churn
122 // when concurrent callers race past a stale disk entry and all try to write.
123 if (unchanged && Date.now() - cached.timestamp < DISK_CACHE_TTL_MS) {
124 return result
125 }
126
127 saveGlobalConfig(current => ({
128 ...current,
129 metricsStatusCache: {
130 enabled: result.enabled,
131 timestamp: Date.now(),
132 },
133 }))
134 return result
135}
136
137/**
138 * Check if metrics are enabled for the current organization.

Callers 1

checkMetricsEnabledFunction · 0.85

Calls 2

getGlobalConfigFunction · 0.50
saveGlobalConfigFunction · 0.50

Tested by

no test coverage detected