Improve relay hygiene and count status

This commit is contained in:
thePR0M3TH3AN committed 2026-01-29 09:58:35 -05:00
1 parent 6ae4b7ab4f
commit c3e986c9d3
12 files changed
+286 -59

No files matched your search

+15
View File
@@ -50,6 +50,7 @@ restoreCacheSnapshot();
* @property {Map<string, number>} dedupeBuckets
* @property {number} lastSyncedAt
* @property {"idle"|"hydrating"|"live"|"stale"} status
* @property {boolean} partial
*/
/**
@@ -278,6 +279,7 @@ function restoreCacheSnapshot() {
dedupeBuckets,
lastSyncedAt,
status: status === "hydrating" || status === "live" ? "idle" : status,
partial: Boolean(state.partial),
});
}
} catch (error) {
@@ -299,6 +301,7 @@ function persistCacheSnapshot() {
dedupeBuckets: Array.from(state.dedupeBuckets.entries()),
lastSyncedAt: state.lastSyncedAt,
status: state.status,
partial: Boolean(state.partial),
},
]);
}
@@ -321,6 +324,7 @@ function ensurePointerState(key) {
dedupeBuckets: new Map(),
lastSyncedAt: 0,
status: "idle",
partial: false,
};
pointerStates.set(key, state);
} else if (!(state.dedupeBuckets instanceof Map)) {
@@ -373,6 +377,7 @@ function notifyHandlers(key) {
total: state.total,
lastSyncedAt: state.lastSyncedAt,
status: state.status,
partial: Boolean(state.partial),
};
for (const handler of listeners.handlers.values()) {
try {
@@ -494,6 +499,15 @@ async function hydratePointer(key, listeners) {
? Number(countResult.total)
: null;
if (countResult && typeof countResult === "object") {
const state = ensurePointerState(key);
const nextPartial = Boolean(countResult.partial);
if (state.partial !== nextPartial) {
state.partial = nextPartial;
mutated = true;
}
}
if (bestCount !== null) {
const state = ensurePointerState(key);
const shouldUpdate = bestCount > state.total || state.total === 0;
@@ -597,6 +611,7 @@ export function subscribeToVideoViewCount(pointerInput, handler, options = {}) {
total: state.total,
lastSyncedAt: state.lastSyncedAt,
status: state.status,
partial: Boolean(state.partial),
});
} catch (error) {
userLogger.warn("[viewCounter] Initial handler invocation threw:", error);