diff --git a/iroh-docs/src/actor.rs b/iroh-docs/src/actor.rs index 04ff497d5f..b6a158a2c7 100644 --- a/iroh-docs/src/actor.rs +++ b/iroh-docs/src/actor.rs @@ -28,7 +28,7 @@ use crate::{ }; const ACTION_CAP: usize = 1024; -const MAX_COMMIT_DELAY: Duration = Duration::from_millis(500); +pub(crate) const MAX_COMMIT_DELAY: Duration = Duration::from_millis(500); #[derive(derive_more::Debug, derive_more::Display)] enum Action { diff --git a/iroh-docs/src/store/fs.rs b/iroh-docs/src/store/fs.rs index 5efe1719b0..c5c4aae245 100644 --- a/iroh-docs/src/store/fs.rs +++ b/iroh-docs/src/store/fs.rs @@ -7,7 +7,6 @@ use std::{ num::NonZeroU64, ops::Bound, path::Path, - time::Duration, }; use anyhow::{anyhow, Result}; @@ -17,6 +16,7 @@ use rand_core::CryptoRngCore; use redb::{Database, DatabaseError, ReadableMultimapTable, ReadableTable, ReadableTableMetadata}; use crate::{ + actor::MAX_COMMIT_DELAY, keys::Author, ranger::{Fingerprint, Range, RangeEntry}, sync::{Entry, EntrySignature, Record, RecordIdentifier, Replica, SignedEntry}, @@ -188,7 +188,7 @@ impl Store { TransactionAndTables::new(tx)? } CurrentTransaction::Write(w) => { - if w.since.elapsed() > Duration::from_millis(500) { + if w.since.elapsed() > MAX_COMMIT_DELAY { tracing::debug!("committing transaction because it's too old"); w.commit()?; let tx = self.db.begin_write()?; @@ -224,7 +224,16 @@ impl Store { let tx = self.db.begin_write()?; TransactionAndTables::new(tx)? } - CurrentTransaction::Write(w) => w, + CurrentTransaction::Write(w) => { + if w.since.elapsed() > MAX_COMMIT_DELAY { + tracing::debug!("committing transaction because it's too old"); + w.commit()?; + let tx = self.db.begin_write()?; + TransactionAndTables::new(tx)? + } else { + w + } + } CurrentTransaction::Read(_) => { let tx = self.db.begin_write()?; TransactionAndTables::new(tx)?