@@ -4,18 +4,19 @@ import type { NextModeTagCache } from "@opennextjs/aws/types/overrides.js";
44import { RecoverableError } from "@opennextjs/aws/utils/error.js" ;
55
66import { getCloudflareContext } from "./cloudflare-context.js" ;
7+ import { DEFAULT_NEXT_CACHE_D1_REVALIDATIONS_TABLE } from "./constants.js" ;
78
89export 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 }
0 commit comments