@@ -123,6 +123,8 @@ impl ImageDownloadHandler {
123123 let ( removed_count, removed_bytes) = if images_dir_size as u64 + image_download_size
124124 > ctx. config ( ) . images . max_cache_size ( )
125125 {
126+ tracing:: info!( image_id=?image_config. id, ?images_dir_size, ?image_download_size, max=?ctx. config( ) . images. max_cache_size( ) , "-------------------------" ) ;
127+
126128 // Fetch as many images as it takes to clear up enough space for this new image.
127129 // Ordered by LRU
128130 let rows = sqlx:: query_as :: < _ , ( Uuid , i64 ) > ( indoc ! (
@@ -148,10 +150,14 @@ impl ImageDownloadHandler {
148150 a.image_id IS NULL
149151 ORDER BY ic.last_used_ts
150152 )
151- SELECT image_id, size
152- FROM cumulative_sizes
153- WHERE running_total - size < ?2
154- ORDER BY last_used_ts
153+ DELETE FROM images_cache
154+ WHERE image_id IN (
155+ SELECT image_id
156+ FROM cumulative_sizes
157+ WHERE running_total - size < ?2
158+ ORDER BY last_used_ts
159+ )
160+ RETURNING image_id, size
155161 " ,
156162 ) )
157163 . bind ( image_config. id )
@@ -171,24 +177,32 @@ impl ImageDownloadHandler {
171177 "no inactive images to delete to make space for new image, downloading anyway" ,
172178 ) ;
173179 } else {
174- tracing:: debug!( count=?rows_len, "cache full, clearing LRU entries" ) ;
180+ tracing:: debug!( image_id=?image_config . id , count=?rows_len, "cache full, clearing LRU entries" ) ;
175181 }
176182
183+ tracing:: info!( image_id=?image_config. id, count=?rows_len, "foo -------------------------" ) ;
184+
177185 let mut total_removed_bytes = 0 ;
178186
179187 for ( image_id, size) in rows {
188+ tracing:: info!( image_id=?image_config. id, image_id2=?image_id, "bar -------------------------" ) ;
189+
180190 total_removed_bytes += size;
181191
182192 // NOTE: The sql query does not return the current image id so there is no chance
183193 // for a deadlock here
184194 // Acquire lock on entry
185195 let entry = self . downloads . entry_async ( image_id) . await ;
186196
197+ tracing:: info!( image_id=?image_config. id, image_id2=?image_id, "bar2 -------------------------" ) ;
198+
187199 match fs:: remove_dir_all ( ctx. image_path ( image_id) ) . await {
188200 Err ( e) if e. kind ( ) == ErrorKind :: NotFound => { }
189201 res => res. context ( "failed to delete image dir" ) ?,
190202 }
191203
204+ tracing:: info!( image_id=?image_config. id, image_id2=?image_id, "bar3 -------------------------" ) ;
205+
192206 // Remove entry and release lock
193207 if let Entry :: Occupied ( entry) = entry {
194208 let _ = entry. remove ( ) ;
@@ -200,6 +214,8 @@ impl ImageDownloadHandler {
200214 ( 0 , 0 )
201215 } ;
202216
217+ tracing:: info!( image_id=?image_config. id, "baz -------------------------" ) ;
218+
203219 metrics:: IMAGE_CACHE_COUNT . set ( cache_count + 1 - removed_count) ;
204220 metrics:: IMAGE_CACHE_SIZE
205221 . set ( images_dir_size + image_download_size as i64 - removed_bytes) ;
@@ -215,8 +231,12 @@ impl ImageDownloadHandler {
215231 . execute ( & mut * tx)
216232 . await ?;
217233
234+ tracing:: info!( image_id=?image_config. id, "baz2 -------------------------" ) ;
235+
218236 tx. commit ( ) . await ?;
219237
238+ tracing:: info!( image_id=?image_config. id, "baz3 -------------------------" ) ;
239+
220240 // Release lock on sqlite pool
221241 drop ( conn) ;
222242
@@ -237,7 +257,7 @@ impl ImageDownloadHandler {
237257 metrics:: IMAGE_CACHE_SIZE . set ( images_dir_size + image_size as i64 - removed_bytes) ;
238258
239259 // Update state to signify download completed successfully
240- let foo = sqlx:: query ( indoc ! (
260+ sqlx:: query ( indoc ! (
241261 "
242262 UPDATE images_cache
243263 SET
0 commit comments