Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Recheck a new keyword's first miss before saving not found (EVE-457) (#1008)
Carter Smith8d6a2ac32727
diff --git a/src/server/workflows/rankCheckPaths.test.ts b/src/server/workflows/rankCheckPaths.test.tsindex 60a0d192..a479d4d7 100644--- a/src/server/workflows/rankCheckPaths.test.ts+++ b/src/server/workflows/rankCheckPaths.test.ts@@ -151,13 +151,13 @@ describe("retryRankChecks", () => {it("retries a device's miss once a retry finds the keyword on the other device", async () => {// Desktop missed on the first check and mobile errored.- mocks.getSnapshotsForRun.mockResolvedValue([snapshot("kw_new", null)]);+ mocks.getSnapshotsForRun.mockResolvedValue([snapshot("kw_never", null)]);// Retry 1 answers mobile at #3; retry 2 answers desktop.queuedResults(3, null);await retryRankChecks(step,- { ...checkContext(["kw_new"]), devices: "both" },+ { ...checkContext(["kw_never"]), devices: "both" },"config_1",);@@ -167,8 +167,21 @@ describe("retryRankChecks", () => {}),);expect(mocks.deleteNotFoundSnapshots).toHaveBeenCalledWith([- { runId: "run_1", trackingKeywordId: "kw_new", device: "desktop" },+ { runId: "run_1", trackingKeywordId: "kw_never", device: "desktop" },+ ]);+ });++ it("finds a new keyword on its second recheck after the first recheck misses", async () => {+ mocks.getSnapshotsForRun.mockResolvedValue([snapshot("kw_new", null)]);+ queuedResults(null, 3);++ await retryRankChecks(step, checkContext(["kw_new"]), "config_1");++ expect(mocks.rankCheckTaskPost).toHaveBeenCalledTimes(2);+ expect(mocks.upsertSnapshots).toHaveBeenCalledWith([+ expect.objectContaining({ trackingKeywordId: "kw_new", position: 3 }),]);+ expect(mocks.deleteNotFoundSnapshots).not.toHaveBeenCalled();});it("never saves a not found for a keyword that ranked before", async () => {diff --git a/src/server/workflows/rankCheckRetries.ts b/src/server/workflows/rankCheckRetries.tsindex 12722977..9c5717b6 100644--- a/src/server/workflows/rankCheckRetries.ts+++ b/src/server/workflows/rankCheckRetries.ts@@ -16,7 +16,9 @@ import {// Retries. A check that errors gets retried, and so does one that reads far// worse than the keyword's known position: Google serves some scraped searches// a fake results page that looks normal but leaves out sites that really rank.-// Retries are billed like any other check, and the best position found wins.+// A keyword with no earlier check has no known position, so its miss is+// rechecked up to RETRY_ROUNDS times. Retries are billed like any other check,+// and the best position found wins.// ---------------------------------------------------------------------------/** A result this many positions below the keyword's known rank is retried. */@@ -32,11 +34,15 @@ interface RetryPair extends RankCheckTaskInput {* or on its other device in this run. Null if it never ranked.*/knownPosition: number | null;+ /** No earlier check, so a miss gets rechecked through all retry rounds. */+ recheckMiss: boolean;}function needsRetry(pair: RetryPair): boolean {if (!pair.answered) return true;- if (pair.knownPosition === null) return false;+ if (pair.knownPosition === null) {+ return pair.recheckMiss && pair.position === null;+ }return (pair.position === null ||pair.position - pair.knownPosition >= RETRY_DROP_POSITIONS@@ -53,9 +59,9 @@ function otherDevice(device: "desktop" | "mobile") {/*** Find the keywords to retry: ones with a device the first check got no answer- * for, or that misses or falls far below the keyword's known position. Both- * devices of each are returned, so a position a retry finds on one can make- * the other's miss suspect.+ * for, that misses or falls far below the keyword's known position, or that+ * misses with no earlier check. Both devices of each are returned, so a+ * position a retry finds on one can make the other's miss suspect.*/async function findRetryPairs(ctx: CheckContext,@@ -83,6 +89,7 @@ async function findRetryPairs(position: currentPositions.get(key(task.keywordId, task.device)) ?? null,answered: currentPositions.has(key(task.keywordId, task.device)),knownPosition: known.length > 0 ? Math.min(...known) : null,+ recheckMiss: !previousPositions.has(task.keywordId),};});const retryKeywords = new Set(@@ -144,12 +151,12 @@ function withOtherDevicePositions(pairs: RetryPair[]): RetryPair[] {}/**- * Retry each keyword/device pair whose check errored or reads far worse than- * its known position, up to RETRY_ROUNDS more times through the task queue- * (queue price, for manual runs too), stopping once a retry settles it. A- * keyword that ranked before is never saved as not found: if no try found it,- * its miss is removed, so it reads as not checked and keeps its previous- * position.+ * Retry each keyword/device pair whose check errored, reads far worse than+ * its known position, or missed on its first check ever, up to RETRY_ROUNDS+ * more times through the task queue (queue price, for manual runs too),+ * stopping once a retry settles it. A keyword that ranked before is never+ * saved as not found: if no try found it, its miss is removed, so it reads as+ * not checked and keeps its previous position.*/export async function retryRankChecks(step: WorkflowStep,