aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/relay.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-24 20:28:36 +0200
committertv <tv@krebsco.de>2026-10-24 20:28:36 +0200
commite63f634ebd3c3de78709e55346226e1d92c5157b (patch)
tree51b8586a1659790ed9d4f99e7490eac3fdb2da07 /src/swarm/relay.rs
parentc274c6be04d4026ad60192218a34739b6083b964 (diff)
cache heads
To reduce the number of write locks, heads are now cached.
Diffstat (limited to 'src/swarm/relay.rs')
-rw-r--r--src/swarm/relay.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/swarm/relay.rs b/src/swarm/relay.rs
index 454a46a..492b59d 100644
--- a/src/swarm/relay.rs
+++ b/src/swarm/relay.rs
@@ -52,6 +52,10 @@ pub(crate) async fn pull_if_behind(state: &AppState, peer: &str, remote: &transp
if remote.epoch != state.local_epoch() || !topology::is_neighbour(state, peer) {
return;
}
+ // The common case, the same heads, needs only the cached heads (read lock).
+ if HeadsSummary::of(state.doc.read().await.heads().to_vec()) == remote.heads {
+ return;
+ }
let missing = match &remote.heads {
HeadsSummary::Heads(heads) => {
// AutoCommit's lookups take &mut self.