@@ -15,7 +15,6 @@ import {
1515 all ,
1616 base64Decode ,
1717 base64Encode ,
18- escapeLike ,
1918 get ,
2019 maybeApply ,
2120 readPrefix ,
@@ -231,12 +230,12 @@ function sqlStmts(db: TypedSql) {
231230 ] ;
232231 // TODO: consider applying same `:start_after IS NULL` trick to KeyValueStore
233232 return db . stmt <
234- { limit : number ; escaped_prefix : string ; start_after : string | null } ,
233+ { limit : number ; prefix : string ; start_after : string | null } ,
235234 Omit < ObjectRow , "blob_id" > & Pick < ObjectRow , ExtraColumns [ number ] >
236235 > ( `
237236 SELECT ${ columns . join ( ", " ) }
238237 FROM _mf_objects
239- WHERE key LIKE :escaped_prefix || '%' ESCAPE '\\'
238+ WHERE substr( key, 1, length(:prefix)) = :prefix
240239 AND (:start_after IS NULL OR key > :start_after)
241240 ORDER BY key LIMIT :limit
242241 ` ) ;
@@ -380,7 +379,6 @@ function sqlStmts(db: TypedSql) {
380379 listMetadata : db . stmt <
381380 {
382381 limit : number ;
383- escaped_prefix : string ;
384382 start_after : string | null ;
385383 prefix : string ;
386384 delimiter : string ;
@@ -407,7 +405,7 @@ function sqlStmts(db: TypedSql) {
407405 -- NOTE: we'll ignore metadata for delimited prefix rows, so it doesn't matter which keys' we return
408406 version, size, etag, uploaded, checksums, http_metadata, custom_metadata
409407 FROM _mf_objects
410- WHERE key LIKE :escaped_prefix || '%' ESCAPE '\\'
408+ WHERE substr( key, 1, length(:prefix)) = :prefix
411409 AND (:start_after IS NULL OR key > :start_after)
412410 GROUP BY delimited_prefix_or_key -- Group keys with same delimited prefix into a row, leaving others in their own rows
413411 ORDER BY last_key LIMIT :limit;
@@ -878,7 +876,7 @@ export class R2BucketObject extends MiniflareDurableObject {
878876
879877 // Run appropriate query depending on options
880878 const params = {
881- escaped_prefix : escapeLike ( prefix ) ,
879+ prefix,
882880 start_after : startAfter ?? null ,
883881 // Increase the queried limit by 1, if we return this many results, we
884882 // know there are more rows. We'll truncate to the original limit before
@@ -891,9 +889,7 @@ export class R2BucketObject extends MiniflareDurableObject {
891889 let nextCursorStartAfter : string | undefined ;
892890
893891 if ( delimiter !== undefined ) {
894- const rows = all (
895- this . #stmts. listMetadata ( { ...params , prefix, delimiter } )
896- ) ;
892+ const rows = all ( this . #stmts. listMetadata ( { ...params , delimiter } ) ) ;
897893
898894 // If there are more results, we'll be returning a cursor
899895 const hasMoreRows = rows . length === limit + 1 ;
0 commit comments