Skip to content

Commit 6ec5431

Browse files
committed
perf: add an index on the tag column in D1 tag cache
1 parent f8280e4 commit 6ec5431

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.changeset/poor-points-work.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
perf: add an index on the tag column in D1 tag cache
6+
7+
It only applies to newly created tables

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class D1NextModeTagCache implements NextModeTagCache {
6363
await db.batch(
6464
tags.map((tag) =>
6565
db
66-
.prepare(`INSERT INTO revalidations (tag, revalidatedAt) VALUES (?, ?)`)
66+
.prepare(`INSERT OR REPLACE INTO revalidations (tag, revalidatedAt) VALUES (?, ?)`)
6767
.bind(this.getCacheKey(tag), Date.now())
6868
)
6969
);

packages/cloudflare/src/cli/commands/populate-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function populateD1TagCache(
254254
[
255255
"d1 execute",
256256
D1_TAG_BINDING_NAME,
257-
`--command "CREATE TABLE IF NOT EXISTS revalidations (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);"`,
257+
`--command "CREATE TABLE IF NOT EXISTS revalidations (tag TEXT PRIMARY KEY, revalidatedAt INTEGER);"`,
258258
`--preview ${populateCacheOptions.shouldUsePreviewId}`,
259259
],
260260
{

0 commit comments

Comments
 (0)