Skip to content

Commit

Permalink
chore: rremove unnecessary checks when sending identification broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
tediou5 committed Jan 17, 2025
1 parent 5f3680b commit d368b04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
27 changes: 5 additions & 22 deletions crates/subspace-farmer/src/cluster/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ where
result = identify_responder(
&nats_client,
cache_id,
&caches_details,
cache_group,
identification_broadcast_interval
).fuse() => {
Expand Down Expand Up @@ -383,16 +382,12 @@ where
///
/// Implementation is using concurrency with multiple tokio tasks, but can be started multiple times
/// per controller instance in order to parallelize more work across threads if needed.
async fn identify_responder<C>(
async fn identify_responder(
nats_client: &NatsClient,
cache_id: CacheId,
caches_details: &[CacheDetails<'_, C>],
cache_group: &str,
identification_broadcast_interval: Duration,
) -> anyhow::Result<()>
where
C: PieceCache,
{
) -> anyhow::Result<()> {
let mut subscription = nats_client
.subscribe_to_broadcasts::<ClusterControllerCacheIdentifyBroadcast>(Some(cache_group), None)
.await
Expand Down Expand Up @@ -423,34 +418,22 @@ where
}

last_identification = Instant::now();
send_identify_broadcast(nats_client, cache_id, caches_details, cache_group).await;
send_identify_broadcast(nats_client, cache_id, cache_group).await;
interval.reset();
}
_ = interval.tick().fuse() => {
last_identification = Instant::now();
trace!("Cache self-identification");

send_identify_broadcast(nats_client, cache_id, caches_details, cache_group).await;
send_identify_broadcast(nats_client, cache_id, cache_group).await;
}
}
}

Ok(())
}

async fn send_identify_broadcast<C>(
nats_client: &NatsClient,
cache_id: CacheId,
caches_details: &[CacheDetails<'_, C>],
cache_group: &str,
) where
C: PieceCache,
{
if caches_details.is_empty() {
warn!("No cache, skip sending cache identify notification");
return;
}

async fn send_identify_broadcast(nats_client: &NatsClient, cache_id: CacheId, cache_group: &str) {
if let Err(error) = nats_client
.broadcast(&ClusterCacheIdentifyBroadcast { cache_id }, cache_group)
.await
Expand Down
5 changes: 0 additions & 5 deletions crates/subspace-farmer/src/cluster/farmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,6 @@ async fn send_identify_broadcast(
farmer_id_string: &str,
farms_details: &[FarmDetails],
) {
if farms_details.is_empty() {
warn!("No farm, skip sending farmer identify notification");
return;
}

if let Err(error) = nats_client
.broadcast(
&new_identify_message(farmer_id, farms_details),
Expand Down

0 comments on commit d368b04

Please sign in to comment.