@@ -14,8 +14,6 @@ import { getCloudflareContext } from "./cloudflare-context.js";
1414 * two columns; `tag`, and `path`. The table name can be configured with `NEXT_CACHE_D1_TAGS_TABLE`
1515 * environment variable.
1616 *
17- * This table should be populated using an SQL file that is generated during the build process.
18- *
1917 * **Tag revalidations**
2018 *
2119 * Revalidation times for tags are stored in a `revalidations` table that contains two columns; `tags`,
@@ -33,7 +31,7 @@ class D1TagCache implements TagCache {
3331
3432 try {
3533 const { success, results } = await db
36- . prepare ( `SELECT tag FROM ${ table . tags } WHERE path = ?` )
34+ . prepare ( `SELECT tag FROM ${ JSON . stringify ( table . tags ) } WHERE path = ?` )
3735 . bind ( path )
3836 . all < { tag : string } > ( ) ;
3937
@@ -57,7 +55,7 @@ class D1TagCache implements TagCache {
5755
5856 try {
5957 const { success, results } = await db
60- . prepare ( `SELECT path FROM ${ table . tags } WHERE tag = ?` )
58+ . prepare ( `SELECT path FROM ${ JSON . stringify ( table . tags ) } WHERE tag = ?` )
6159 . bind ( tag )
6260 . all < { path : string } > ( ) ;
6361
@@ -80,9 +78,9 @@ class D1TagCache implements TagCache {
8078 try {
8179 const { success, results } = await db
8280 . prepare (
83- `SELECT ${ table . revalidations } .tag FROM ${ table . revalidations }
84- INNER JOIN ${ table . tags } ON ${ table . revalidations } .tag = ${ table . tags } .tag
85- WHERE ${ table . tags } .path = ? AND ${ table . revalidations } .revalidatedAt > ?;`
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 > ?;`
8684 )
8785 . bind ( this . getCacheKey ( path ) , lastModified ?? 0 )
8886 . all < { tag : string } > ( ) ;
@@ -109,15 +107,15 @@ class D1TagCache implements TagCache {
109107 if ( revalidatedAt === 1 ) {
110108 // new tag/path mapping from set
111109 return db
112- . prepare ( `INSERT INTO ${ table . tags } (tag, path) VALUES (?, ?)` )
110+ . prepare ( `INSERT INTO ${ JSON . stringify ( table . tags ) } (tag, path) VALUES (?, ?)` )
113111 . bind ( this . getCacheKey ( tag ) , this . getCacheKey ( path ) ) ;
114112 }
115113
116114 if ( ! uniqueTags . has ( tag ) && revalidatedAt !== - 1 ) {
117115 // tag was revalidated
118116 uniqueTags . add ( tag ) ;
119117 return db
120- . prepare ( `INSERT INTO ${ table . revalidations } (tag, revalidatedAt) VALUES (?, ?)` )
118+ . prepare ( `INSERT INTO ${ JSON . stringify ( table . revalidations ) } (tag, revalidatedAt) VALUES (?, ?)` )
121119 . bind ( this . getCacheKey ( tag ) , revalidatedAt ?? Date . now ( ) ) ;
122120 }
123121 } )
@@ -151,8 +149,8 @@ class D1TagCache implements TagCache {
151149 isDisabled : false as const ,
152150 db,
153151 table : {
154- tags : JSON . stringify ( cfEnv . NEXT_CACHE_D1_TAGS_TABLE ?? "tags" ) ,
155- revalidations : JSON . stringify ( cfEnv . NEXT_CACHE_D1_REVALIDATIONS_TABLE ?? "revalidations" ) ,
152+ tags : cfEnv . NEXT_CACHE_D1_TAGS_TABLE ?? "tags" ,
153+ revalidations : cfEnv . NEXT_CACHE_D1_REVALIDATIONS_TABLE ?? "revalidations" ,
156154 } ,
157155 } ;
158156 }
0 commit comments