@@ -261,11 +261,23 @@ 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+ if !trim_requests. contains( & site) {
274+ trim_requests. push_back( site) ;
275+ }
276+ // Schedule Trim only if there is no other request in the scheduler
277+ if request_scheduler. inflight. is_empty( )
278+ && let Some ( site) = trim_requests. pop_front( ) {
279+ request_scheduler. schedule_new( site, Request :: Trim ) ;
280+ }
269281 }
270282 DirtyLogCommand :: Get { site, response_tx } => {
271283 request_scheduler. schedule_new( site, Request :: Get ( response_tx) ) ;
@@ -290,6 +302,12 @@ pub(crate) async fn dirtylog_task(
290302 } ,
291303 site = request_scheduler. inflight. select_next_some( ) => {
292304 request_scheduler. on_finished( site) ;
305+ // If no other requests have been scheduled, we can process another Trim
306+ if request_scheduler. inflight. is_empty( )
307+ && let Some ( site) = trim_requests. pop_front( ) {
308+ request_scheduler. schedule_new( site, Request :: Trim ) ;
309+ }
310+
293311 }
294312 complete => break ,
295313 }
0 commit comments