diff options
| author | tv <tv@krebsco.de> | 2026-10-24 20:28:36 +0200 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-24 20:28:36 +0200 |
| commit | e63f634ebd3c3de78709e55346226e1d92c5157b (patch) | |
| tree | 51b8586a1659790ed9d4f99e7490eac3fdb2da07 /src/swarm/peer.rs | |
| parent | c274c6be04d4026ad60192218a34739b6083b964 (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.rs | 8 |
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, ) }; |
