Skip to content

Commit 631ed21

Browse files
committed
rename to tables
1 parent 4f8bddc commit 631ed21

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ class D1TagCache implements TagCache {
2424
public readonly name = "d1-tag-cache";
2525

2626
public async getByPath(rawPath: string): Promise<string[]> {
27-
const { isDisabled, db, table } = this.getConfig();
27+
const { isDisabled, db, tables } = this.getConfig();
2828
if (isDisabled) return [];
2929

3030
const path = this.getCacheKey(rawPath);
3131

3232
try {
3333
const { success, results } = await db
34-
.prepare(`SELECT tag FROM ${JSON.stringify(table.tags)} WHERE path = ?`)
34+
.prepare(`SELECT tag FROM ${JSON.stringify(tables.tags)} WHERE path = ?`)
3535
.bind(path)
3636
.all<{ tag: string }>();
3737

@@ -48,14 +48,14 @@ class D1TagCache implements TagCache {
4848
}
4949

5050
public async getByTag(rawTag: string): Promise<string[]> {
51-
const { isDisabled, db, table } = this.getConfig();
51+
const { isDisabled, db, tables } = this.getConfig();
5252
if (isDisabled) return [];
5353

5454
const tag = this.getCacheKey(rawTag);
5555

5656
try {
5757
const { success, results } = await db
58-
.prepare(`SELECT path FROM ${JSON.stringify(table.tags)} WHERE tag = ?`)
58+
.prepare(`SELECT path FROM ${JSON.stringify(tables.tags)} WHERE tag = ?`)
5959
.bind(tag)
6060
.all<{ path: string }>();
6161

@@ -72,15 +72,15 @@ class D1TagCache implements TagCache {
7272
}
7373

7474
public async getLastModified(path: string, lastModified?: number): Promise<number> {
75-
const { isDisabled, db, table } = this.getConfig();
75+
const { isDisabled, db, tables } = this.getConfig();
7676
if (isDisabled) return lastModified ?? Date.now();
7777

7878
try {
7979
const { success, results } = await db
8080
.prepare(
81-
`SELECT ${JSON.stringify(table.revalidations)}.tag FROM ${JSON.stringify(table.revalidations)}
82-
INNER JOIN ${JSON.stringify(table.tags)} ON ${JSON.stringify(table.revalidations)}.tag = ${JSON.stringify(table.tags)}.tag
83-
WHERE ${JSON.stringify(table.tags)}.path = ? AND ${JSON.stringify(table.revalidations)}.revalidatedAt > ?;`
81+
`SELECT ${JSON.stringify(tables.revalidations)}.tag FROM ${JSON.stringify(tables.revalidations)}
82+
INNER JOIN ${JSON.stringify(tables.tags)} ON ${JSON.stringify(tables.revalidations)}.tag = ${JSON.stringify(tables.tags)}.tag
83+
WHERE ${JSON.stringify(tables.tags)}.path = ? AND ${JSON.stringify(tables.revalidations)}.revalidatedAt > ?;`
8484
)
8585
.bind(this.getCacheKey(path), lastModified ?? 0)
8686
.all<{ tag: string }>();
@@ -96,7 +96,7 @@ class D1TagCache implements TagCache {
9696
}
9797

9898
public async writeTags(tags: { tag: string; path: string; revalidatedAt?: number }[]): Promise<void> {
99-
const { isDisabled, db, table } = this.getConfig();
99+
const { isDisabled, db, tables } = this.getConfig();
100100
if (isDisabled || tags.length === 0) return;
101101

102102
try {
@@ -107,15 +107,17 @@ class D1TagCache implements TagCache {
107107
if (revalidatedAt === 1) {
108108
// new tag/path mapping from set
109109
return db
110-
.prepare(`INSERT INTO ${JSON.stringify(table.tags)} (tag, path) VALUES (?, ?)`)
110+
.prepare(`INSERT INTO ${JSON.stringify(tables.tags)} (tag, path) VALUES (?, ?)`)
111111
.bind(this.getCacheKey(tag), this.getCacheKey(path));
112112
}
113113

114114
if (!uniqueTags.has(tag) && revalidatedAt !== -1) {
115115
// tag was revalidated
116116
uniqueTags.add(tag);
117117
return db
118-
.prepare(`INSERT INTO ${JSON.stringify(table.revalidations)} (tag, revalidatedAt) VALUES (?, ?)`)
118+
.prepare(
119+
`INSERT INTO ${JSON.stringify(tables.revalidations)} (tag, revalidatedAt) VALUES (?, ?)`
120+
)
119121
.bind(this.getCacheKey(tag), revalidatedAt ?? Date.now());
120122
}
121123
})
@@ -148,7 +150,7 @@ class D1TagCache implements TagCache {
148150
return {
149151
isDisabled: false as const,
150152
db,
151-
table: {
153+
tables: {
152154
tags: cfEnv.NEXT_CACHE_D1_TAGS_TABLE ?? "tags",
153155
revalidations: cfEnv.NEXT_CACHE_D1_REVALIDATIONS_TABLE ?? "revalidations",
154156
},

0 commit comments

Comments
 (0)