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
5 changes: 5 additions & 0 deletions .changeset/great-eyes-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

refactor: account for empty tag list in tag cache
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export class D1NextModeTagCache implements NextModeTagCache {

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

async hasBeenRevalidated(tags: string[], lastModified?: number): Promise<boolean> {
const { isDisabled, db } = this.getConfig();
if (isDisabled) return false;
if (isDisabled || tags.length === 0) {
return false;
}
try {
const result = await db
.prepare(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ class ShardedDOTagCache implements NextModeTagCache {

public async getLastRevalidated(tags: string[]): Promise<number> {
const { isDisabled } = this.getConfig();
if (isDisabled) return 0;
if (tags.length === 0) return 0; // No tags to check
if (isDisabled || tags.length === 0) {
return 0;
}
const deduplicatedTags = Array.from(new Set(tags)); // We deduplicate the tags to avoid unnecessary requests
try {
const shardedTagGroups = this.groupTagsByDO({ tags: deduplicatedTags });
Expand Down Expand Up @@ -177,7 +178,9 @@ class ShardedDOTagCache implements NextModeTagCache {
*/
public async hasBeenRevalidated(tags: string[], lastModified?: number): Promise<boolean> {
const { isDisabled } = this.getConfig();
if (isDisabled) return false;
if (isDisabled || tags.length === 0) {
return false;
}
try {
const shardedTagGroups = this.groupTagsByDO({ tags });
const shardedTagRevalidationOutcomes = await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class KVNextModeTagCache implements NextModeTagCache {

async getLastRevalidated(tags: string[]): Promise<number> {
const kv = this.getKv();
if (!kv) {
if (!kv || tags.length === 0) {
return 0;
}

Expand Down