Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/server/features/domain/services/DomainService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { waitUntil } from "cloudflare:workers";
import { buildCacheKey, getCached, setCached } from "@/server/lib/r2-cache";
import { z } from "zod";
import type { BillingCustomerContext } from "@/server/billing/subscription";
Expand Down Expand Up @@ -90,10 +91,14 @@ async function getOverview(
};

if (result.hasData) {
void setCached(cacheKey, result, DOMAIN_OVERVIEW_TTL_SECONDS).catch(
(error) => {
console.error("domain.overview.cache-write failed:", error);
},
// waitUntil, not void: workerd cancels unregistered pending I/O once the
// response is sent, so a fire-and-forget put never persists the cache.
waitUntil(
setCached(cacheKey, result, DOMAIN_OVERVIEW_TTL_SECONDS).catch(
(error) => {
console.error("domain.overview.cache-write failed:", error);
},
),
);
}

Expand Down Expand Up @@ -174,10 +179,15 @@ async function getSuggestedKeywords(
}));

if (keywords.length > 0) {
void setCached(cacheKey, keywords, DOMAIN_OVERVIEW_TTL_SECONDS).catch(
(error) => {
console.error("domain.keyword-suggestions.cache-write failed:", error);
},
waitUntil(
setCached(cacheKey, keywords, DOMAIN_OVERVIEW_TTL_SECONDS).catch(
(error) => {
console.error(
"domain.keyword-suggestions.cache-write failed:",
error,
);
},
),
);
}

Expand Down
13 changes: 9 additions & 4 deletions src/server/features/domain/services/domainKeywordsPage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { waitUntil } from "cloudflare:workers";
import { z } from "zod";
import type { BillingCustomerContext } from "@/server/billing/subscription";
import { createDataforseoClient } from "@/server/lib/dataforseo";
Expand Down Expand Up @@ -113,10 +114,14 @@ export async function getKeywordsPage(
fetchedAt: new Date().toISOString(),
};

void setCached(cacheKey, result, DOMAIN_KEYWORDS_PAGE_TTL_SECONDS).catch(
(error) => {
console.error("domain.keywords-page.cache-write failed:", error);
},
// waitUntil, not void: workerd cancels unregistered pending I/O once the
// response is sent, so a fire-and-forget put never persists the cache.
waitUntil(
setCached(cacheKey, result, DOMAIN_KEYWORDS_PAGE_TTL_SECONDS).catch(
(error) => {
console.error("domain.keywords-page.cache-write failed:", error);
},
),
);

return result;
Expand Down
13 changes: 9 additions & 4 deletions src/server/features/domain/services/domainPagesPage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { waitUntil } from "cloudflare:workers";
import { z } from "zod";
import type { BillingCustomerContext } from "@/server/billing/subscription";
import { createDataforseoClient } from "@/server/lib/dataforseo";
Expand Down Expand Up @@ -193,10 +194,14 @@ export async function getPagesPage(
fetchedAt: new Date().toISOString(),
};

void setCached(cacheKey, result, DOMAIN_PAGES_PAGE_TTL_SECONDS).catch(
(error) => {
console.error("domain.pages-page.cache-write failed:", error);
},
// waitUntil, not void: workerd cancels unregistered pending I/O once the
// response is sent, so a fire-and-forget put never persists the cache.
waitUntil(
setCached(cacheKey, result, DOMAIN_PAGES_PAGE_TTL_SECONDS).catch(
(error) => {
console.error("domain.pages-page.cache-write failed:", error);
},
),
);

return result;
Expand Down
11 changes: 8 additions & 3 deletions src/server/features/keywords/services/research/serp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { waitUntil } from "cloudflare:workers";
import { type SerpLiveItem } from "@/server/lib/dataforseo";
import { buildCacheKey, getCached, setCached } from "@/server/lib/r2-cache";
import type { SerpResultItem } from "@/types/keywords";
Expand Down Expand Up @@ -91,9 +92,13 @@ async function getSerpLiveAnalysis(
result.reason = "no_organic_results";
}

void setCached(cacheKey, result, SERP_CACHE_TTL_SECONDS).catch((error) => {
console.error("keywords.serp.cache-write failed:", error);
});
// waitUntil, not void: workerd cancels unregistered pending I/O once the
// response is sent, so a fire-and-forget put never persists the cache.
waitUntil(
setCached(cacheKey, result, SERP_CACHE_TTL_SECONDS).catch((error) => {
console.error("keywords.serp.cache-write failed:", error);
}),
);

return result;
}
Expand Down
Loading