From ebdada2af486b5bf6a8b9f47b2e712be572d8b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Sun, 1 Dec 2024 13:24:32 +0100 Subject: [PATCH] Make sync TR --- lib/db/sync.ml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/db/sync.ml b/lib/db/sync.ml index 0f0b965..d29791f 100644 --- a/lib/db/sync.ml +++ b/lib/db/sync.ml @@ -484,7 +484,7 @@ let sync_v2 ~report ~(source : Source.connexion) idb = done in let renaming () = Queue.length queue + !running_jobs in - let rec assign_work () = + let rec assign_work acc () = (* Throttle queries *) let* () = let timer, timeout = Fut.create () in @@ -494,7 +494,7 @@ let sync_v2 ~report ~(source : Source.connexion) idb = (* Wait for a worker *) let next_worker = Queue.take_opt workers in match next_worker with - | None -> Fut.ok () + | None -> acc | Some next_worker -> ( let future_worker, worker_is_ready = Fut.create () in let () = Queue.add future_worker workers in @@ -502,7 +502,7 @@ let sync_v2 ~report ~(source : Source.connexion) idb = match Queue.take_opt queue with | None -> worker_is_ready worker; - Fut.ok () + acc | Some job -> let () = report @@ -515,13 +515,11 @@ let sync_v2 ~report ~(source : Source.connexion) idb = in let worker = let* () = run_job ~worker ~worker_is_ready job in - (assign_work [@tailcall]) () + (assign_work (Fut.ok ()) [@tailcall]) () in - let* () = assign_work () in - let+ () = worker in - ()) + (assign_work (Fut.bind acc (fun _ -> worker)) [@tailcall]) ()) in - assign_work () + assign_work (Fut.ok ()) () in let+ () = sync_all ~threads:100 in Console.log [ "Sync finished. Added "; !count_tracks; " tracks" ]