@@ -261,11 +261,21 @@ pub(crate) async fn dirtylog_task(
261261
262262 let mut request_scheduler = RequestScheduler :: new ( Path :: new ( & app_state. config . journal_dir ) . into ( ) ) ;
263263
264+ // Priority-based execution:
265+ // 1. High Priority: Get, ProcessNotification (Optimizes getLog responsiveness)
266+ // 2. Low Priority: Trim (Processed sequentially)
267+ let mut trim_requests = VecDeque :: new ( ) ;
268+
264269 loop {
265- futures:: select ! {
270+ futures:: select_biased ! {
266271 command = cmd_rx. select_next_some( ) => match command {
267272 DirtyLogCommand :: Trim { site } => {
268- request_scheduler. schedule_new( site, Request :: Trim ) ;
273+ trim_requests. push_back( site) ;
274+ // Schedule Trim only if there is no other request in the scheduler
275+ if request_scheduler. inflight. is_empty( )
276+ && let Some ( site) = trim_requests. pop_front( ) {
277+ request_scheduler. schedule_new( site, Request :: Trim ) ;
278+ }
269279 }
270280 DirtyLogCommand :: Get { site, response_tx } => {
271281 request_scheduler. schedule_new( site, Request :: Get ( response_tx) ) ;
@@ -290,6 +300,12 @@ pub(crate) async fn dirtylog_task(
290300 } ,
291301 site = request_scheduler. inflight. select_next_some( ) => {
292302 request_scheduler. on_finished( site) ;
303+ // If no other requests have been scheduled, we can process another Trim
304+ if request_scheduler. inflight. is_empty( )
305+ && let Some ( site) = trim_requests. pop_front( ) {
306+ request_scheduler. schedule_new( site, Request :: Trim ) ;
307+ }
308+
293309 }
294310 complete => break ,
295311 }
0 commit comments