@@ -144,6 +144,7 @@ impl FileSystem {
144144
145145 // If not in local fs and we have db_fs, check database
146146 if !local_exists {
147+ log:: debug!( "File {path:?} not found in local filesystem, checking database" ) ;
147148 if let Some ( db_fs) = & self . db_fs_queries {
148149 return db_fs. file_exists ( app_state, path) . await ;
149150 }
@@ -226,7 +227,7 @@ impl DbFsQueries {
226227 db_kind : AnyKind ,
227228 ) -> anyhow:: Result < AnyStatement < ' static > > {
228229 let exists_query = format ! (
229- "SELECT 1 from sqlpage_files WHERE path = {}" ,
230+ "SELECT 1 from sqlpage_files WHERE path = {} LIMIT 1 " ,
230231 make_placeholder( db_kind, 1 ) ,
231232 ) ;
232233 let param_types: & [ AnyTypeInfo ; 1 ] = & [ <str as Type < Postgres > >:: type_info ( ) . into ( ) ] ;
@@ -282,11 +283,20 @@ impl DbFsQueries {
282283 }
283284
284285 async fn file_exists ( & self , app_state : & AppState , path : & Path ) -> anyhow:: Result < bool > {
285- self . exists
286+ let query = self
287+ . exists
286288 . query_as :: < ( i32 , ) > ( )
287- . bind ( path. display ( ) . to_string ( ) )
288- . fetch_optional ( & app_state. db . connection )
289- . await
289+ . bind ( path. display ( ) . to_string ( ) ) ;
290+ log:: trace!(
291+ "Checking if file {path:?} exists by executing query: \n \
292+ {}\n \
293+ with parameters: {:?}",
294+ self . exists. sql( ) ,
295+ ( path, )
296+ ) ;
297+ let result = query. fetch_optional ( & app_state. db . connection ) . await ;
298+ log:: debug!( "DB File exists result: {:?}" , result) ;
299+ result
290300 . map ( |result| result. is_some ( ) )
291301 . with_context ( || format ! ( "Unable to check if {path:?} exists in the database" ) )
292302 }
0 commit comments