Skip to content

Commit eeb18bb

Browse files
authored
refactor: account for empty tag list in tag cache (#918)
1 parent 5d0042b commit eeb18bb

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

.changeset/great-eyes-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
refactor: account for empty tag list in tag cache

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export class D1NextModeTagCache implements NextModeTagCache {
1414

1515
async getLastRevalidated(tags: string[]): Promise<number> {
1616
const { isDisabled, db } = this.getConfig();
17-
if (isDisabled) return 0;
17+
if (isDisabled || tags.length === 0) {
18+
return 0;
19+
}
1820
try {
1921
const result = await db
2022
.prepare(
@@ -36,7 +38,9 @@ export class D1NextModeTagCache implements NextModeTagCache {
3638

3739
async hasBeenRevalidated(tags: string[], lastModified?: number): Promise<boolean> {
3840
const { isDisabled, db } = this.getConfig();
39-
if (isDisabled) return false;
41+
if (isDisabled || tags.length === 0) {
42+
return false;
43+
}
4044
try {
4145
const result = await db
4246
.prepare(

packages/cloudflare/src/api/overrides/tag-cache/do-sharded-tag-cache.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ class ShardedDOTagCache implements NextModeTagCache {
130130

131131
public async getLastRevalidated(tags: string[]): Promise<number> {
132132
const { isDisabled } = this.getConfig();
133-
if (isDisabled) return 0;
134-
if (tags.length === 0) return 0; // No tags to check
133+
if (isDisabled || tags.length === 0) {
134+
return 0;
135+
}
135136
const deduplicatedTags = Array.from(new Set(tags)); // We deduplicate the tags to avoid unnecessary requests
136137
try {
137138
const shardedTagGroups = this.groupTagsByDO({ tags: deduplicatedTags });
@@ -177,7 +178,9 @@ class ShardedDOTagCache implements NextModeTagCache {
177178
*/
178179
public async hasBeenRevalidated(tags: string[], lastModified?: number): Promise<boolean> {
179180
const { isDisabled } = this.getConfig();
180-
if (isDisabled) return false;
181+
if (isDisabled || tags.length === 0) {
182+
return false;
183+
}
181184
try {
182185
const shardedTagGroups = this.groupTagsByDO({ tags });
183186
const shardedTagRevalidationOutcomes = await Promise.all(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class KVNextModeTagCache implements NextModeTagCache {
2626

2727
async getLastRevalidated(tags: string[]): Promise<number> {
2828
const kv = this.getKv();
29-
if (!kv) {
29+
if (!kv || tags.length === 0) {
3030
return 0;
3131
}
3232

0 commit comments

Comments
 (0)