Merge pull request #1481 from PR0M3TH3AN/jules/watch-history-reliability-8717302607974193984

Improve Watch History Reliability and Responsiveness
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-21 17:10:34 -05:00
commit 7f2ba67323
3 files changed
+24 -9

No files matched your search

+19 -7
View File
@@ -1101,13 +1101,25 @@ class WatchHistoryManager {
if (attempt > WATCH_HISTORY_REPUBLISH_MAX_ATTEMPTS) {
return;
}
const exponentialDelay = WATCH_HISTORY_REPUBLISH_BASE_DELAY_MS * Math.pow(2, attempt);
const cappedDelay = Math.min(exponentialDelay, WATCH_HISTORY_REPUBLISH_MAX_DELAY_MS);
const jitter = Math.random() * cappedDelay * WATCH_HISTORY_REPUBLISH_JITTER;
const delay = Math.max(
WATCH_HISTORY_REPUBLISH_BASE_DELAY_MS,
Math.floor(cappedDelay + jitter),
);
let delay = 0;
if (attempt === 0) {
delay = 10;
} else {
const exponentialDelay =
WATCH_HISTORY_REPUBLISH_BASE_DELAY_MS * Math.pow(2, attempt);
const cappedDelay = Math.min(
exponentialDelay,
WATCH_HISTORY_REPUBLISH_MAX_DELAY_MS,
);
const jitter =
Math.random() * cappedDelay * WATCH_HISTORY_REPUBLISH_JITTER;
delay = Math.max(
WATCH_HISTORY_REPUBLISH_BASE_DELAY_MS,
Math.floor(cappedDelay + jitter),
);
}
if (onSchedule) {
try {
onSchedule({ taskId: key, attempt: attempt + 1, delay });
+1 -1
View File
@@ -5,7 +5,7 @@ import {
ingestLocalViewEvent as defaultIngestLocalViewEvent,
} from "../viewCounter.js";
const DEFAULT_VIEW_THRESHOLD_SECONDS = 12;
const DEFAULT_VIEW_THRESHOLD_SECONDS = 5;
function normalizeString(value) {
return typeof value === "string" ? value.trim() : "";
+4 -1
View File
@@ -615,12 +615,15 @@ function scheduleRepublishForQueue(actorKey) {
actorKey,
queue,
keysToClear,
snapshotStartTime
snapshotStartTime,
);
await updateFingerprintCache(
actorKey,
publishResult.items || latestItems,
);
if (queue.items.size > 0) {
scheduleRepublishForQueue(actorKey);
}
} else if (!publishResult?.retryable) {
// If not retryable, we clear the scheduled flag to allow new attempts later
queue.republishScheduled = false;