Skip to content

Commit b80781a

Browse files
committed
review
1 parent b1bd2a0 commit b80781a

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const DEFAULT_NEXT_CACHE_D1_REVALIDATIONS_TABLE = "revalidations";

packages/cloudflare/src/api/d1-next-tag-cache.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ import type { NextModeTagCache } from "@opennextjs/aws/types/overrides.js";
44
import { RecoverableError } from "@opennextjs/aws/utils/error.js";
55

66
import { getCloudflareContext } from "./cloudflare-context.js";
7+
import { DEFAULT_NEXT_CACHE_D1_REVALIDATIONS_TABLE } from "./constants.js";
78

89
export class D1NextModeTagCache implements NextModeTagCache {
9-
mode = "nextMode" as const;
10-
name = "d1-next-mode-tag-cache";
10+
readonly mode = "nextMode" as const;
11+
readonly name = "d1-next-mode-tag-cache";
1112

1213
async hasBeenRevalidated(tags: string[], lastModified?: number): Promise<boolean> {
1314
const { isDisabled, db, tables } = this.getConfig();
1415
if (isDisabled) return false;
1516
try {
1617
const result = await db
1718
.prepare(
18-
`SELECT COUNT(*) as cnt FROM ${JSON.stringify(tables.revalidations)} WHERE tag IN (${tags.map(() => "?").join(", ")}) AND revalidatedAt > ?`
19+
`SELECT COUNT(*) as cnt FROM ${JSON.stringify(tables.revalidations)} WHERE tag IN (${tags.map(() => "?").join(", ")}) AND revalidatedAt > ? LIMIT 1`
1920
)
2021
.bind(...tags.map((tag) => this.getCacheKey(tag)), lastModified ?? Date.now())
2122
.first<{ cnt: number }>();
@@ -60,7 +61,7 @@ export class D1NextModeTagCache implements NextModeTagCache {
6061
isDisabled: false as const,
6162
db,
6263
tables: {
63-
revalidations: cfEnv.NEXT_CACHE_D1_REVALIDATIONS_TABLE ?? "revalidations",
64+
revalidations: cfEnv.NEXT_CACHE_D1_REVALIDATIONS_TABLE ?? DEFAULT_NEXT_CACHE_D1_REVALIDATIONS_TABLE,
6465
},
6566
};
6667
}

packages/cloudflare/src/api/d1-tag-cache.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { OriginalTagCache } from "@opennextjs/aws/types/overrides.js";
44
import { RecoverableError } from "@opennextjs/aws/utils/error.js";
55

66
import { getCloudflareContext } from "./cloudflare-context.js";
7+
import { DEFAULT_NEXT_CACHE_D1_REVALIDATIONS_TABLE } from "./constants.js";
78

89
/**
910
* An instance of the Tag Cache that uses a D1 binding (`NEXT_CACHE_D1`) as it's underlying data store.
@@ -154,7 +155,7 @@ class D1TagCache implements OriginalTagCache {
154155
db,
155156
tables: {
156157
tags: cfEnv.NEXT_CACHE_D1_TAGS_TABLE ?? "tags",
157-
revalidations: cfEnv.NEXT_CACHE_D1_REVALIDATIONS_TABLE ?? "revalidations",
158+
revalidations: cfEnv.NEXT_CACHE_D1_REVALIDATIONS_TABLE ?? DEFAULT_NEXT_CACHE_D1_REVALIDATIONS_TABLE,
158159
},
159160
};
160161
}

0 commit comments

Comments
 (0)