MCPcopy Index your code
hub / github.com/codeaashu/claude-code / refreshMetricsStatus

Function refreshMetricsStatus

src/services/api/metricsOptOut.ts:94–116  ·  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

92 * known-good disk value.
93 */
94async function refreshMetricsStatus(): Promise<MetricsStatus> {
95 const result = await memoizedCheckMetrics()
96 if (result.hasError) {
97 return result
98 }
99
100 const cached = getGlobalConfig().metricsStatusCache
101 const unchanged = cached !== undefined && cached.enabled === result.enabled
102 // Skip write when unchanged AND timestamp still fresh — avoids config churn
103 // when concurrent callers race past a stale disk entry and all try to write.
104 if (unchanged && Date.now() - cached.timestamp < DISK_CACHE_TTL_MS) {
105 return result
106 }
107
108 saveGlobalConfig(current => ({
109 ...current,
110 metricsStatusCache: {
111 enabled: result.enabled,
112 timestamp: Date.now(),
113 },
114 }))
115 return result
116}
117
118/**
119 * Check if metrics are enabled for the current organization.

Callers 1

checkMetricsEnabledFunction · 0.85

Calls 2

getGlobalConfigFunction · 0.85
saveGlobalConfigFunction · 0.85

Tested by

no test coverage detected