From 23db8bcda05e7bb89836ded7141af5fb0c880439 Mon Sep 17 00:00:00 2001 From: "Willow (GHOST)" Date: Sun, 26 Jul 2026 20:56:05 +0100 Subject: [PATCH] fix(uplc): auto refresh stats every 500000 ops to help mitigate drift --- uplc/src/plc.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/uplc/src/plc.rs b/uplc/src/plc.rs index fab4ace..d6311eb 100644 --- a/uplc/src/plc.rs +++ b/uplc/src/plc.rs @@ -83,6 +83,22 @@ pub async fn run_plc_sync(db: DB, stats: Arc>) -> Result<()> { let mut total = 0; loop { + // todo this won't hold up after the backfill as it'll be slower + // and we likely won't get full batches. + if total % 500_000 == 0 { + println!("refreshing stats at {} ops", total); + + tokio::task::spawn_blocking({ + let db = db.clone(); + let mut stats = stats.clone().write_owned().await; + // todo this does make the api unavailable while it's working + // as the rwlock doesn't allow any readers while a writer is open + move || async move { stats.refresh(&db) } + }) + .await? + .await?; + } + println!("seen {} this session with seq {}", total, after); let url = format!("https://plc.directory/export?count=1000&after={}", after); -- knotmirror 0.0.1