summaryrefslogtreecommitdiffstats
path: root/src/swarm/peer.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
commit59c1511bcacedddc354e82033d523f459c6db5d4 (patch)
treefae84e91e1c7f4a98b2e99c79602ace059c6e211 /src/swarm/peer.rs
parent8e8aee67ef8dfa7c30a3734a4b6f5357c87f1a67 (diff)
cache heads
To reduce the number of write locks, heads are now cached.
Diffstat (limited to 'src/swarm/peer.rs')
-rw-r--r--src/swarm/peer.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/swarm/peer.rs b/src/swarm/peer.rs
index dd70bbb..3d7da32 100644
--- a/src/swarm/peer.rs
+++ b/src/swarm/peer.rs
@@ -108,12 +108,12 @@ pub(crate) async fn send_ping(state: &AppState, peer: &str) -> Result<()> {
/// Our keepalive for `peer`.
pub(crate) async fn local_keepalive(state: &AppState, peer: &str) -> transport::Keepalive {
- // AutoCommit::get_heads takes &mut self (it closes the pending transaction).
- // Heads and epoch come from the same locked replica, so they always match.
+ // Heads and epoch come from the same locked replica, so they always match. The heads
+ // are cached (`Replica`), so the read lock is enough.
let (heads, epoch) = {
- let mut replica = state.doc.write().await;
+ let replica = state.doc.read().await;
(
- transport::HeadsSummary::of(replica.doc.get_heads()),
+ transport::HeadsSummary::of(replica.heads().to_vec()),
replica.epoch,
)
};