@yemi33/minions 0.1.1996 → 0.1.1998

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -150,9 +150,31 @@ function _processStatusUpdate(data) {
150
150
  }
151
151
 
152
152
  let _knownDashboardStartId = null;
153
+ // /api/status ETag cache (W-mpehsyhv0017085a). The dashboard polls every 4 s
154
+ // but the server-side cache only changes every 10–60 s. Sending If-None-Match
155
+ // lets the server short-circuit ~60 %+ of polls into a 304 with no body —
156
+ // drops the 7.7 MB JSON.stringify + gzipSync off the dashboard event loop on
157
+ // the hot path. Falls back to the cached payload on 304; transparent to all
158
+ // downstream consumers of `data`.
159
+ let _lastStatusEtag = null;
160
+ let _lastStatusData = null;
153
161
  async function refresh() {
154
162
  try {
155
- const data = await safeFetch('/api/status').then(r => r.json());
163
+ const headers = {};
164
+ if (_lastStatusEtag) headers['If-None-Match'] = _lastStatusEtag;
165
+ const res = await safeFetch('/api/status', { headers });
166
+ let data;
167
+ if (res.status === 304 && _lastStatusData) {
168
+ // Cache hit — reuse last payload, skip parsing entirely.
169
+ data = _lastStatusData;
170
+ } else {
171
+ data = await res.json();
172
+ const etag = res.headers && (res.headers.get ? res.headers.get('etag') : null);
173
+ if (etag) {
174
+ _lastStatusEtag = etag;
175
+ _lastStatusData = data;
176
+ }
177
+ }
156
178
  // Auto-reload when dashboard restarts (stale connections cause "Failed to fetch" on CC/doc-chat)
157
179
  const dashId = (data.version && data.version.dashboardStartedAt) || null;
158
180
  if (dashId && _knownDashboardStartId && dashId !== _knownDashboardStartId) {