node: Skip fetch early if no refs in announcement

This commit is contained in:
cloudhead 2024-04-05 12:17:17 +02:00
parent e55c86f1ce
commit bc247dff24
No known key found for this signature in database
1 changed files with 15 additions and 15 deletions

View File

@ -1411,6 +1411,11 @@ where
refs: message.refs.to_vec(), refs: message.refs.to_vec(),
timestamp: message.timestamp, timestamp: message.timestamp,
}); });
// Empty announcements can be safely ignored.
let Some(refs) = NonEmpty::from_vec(message.refs.to_vec()) else {
debug!(target: "service", "Skipping fetch, no refs in announcement for {}", message.rid);
return Ok(false);
};
// We update inventories when receiving ref announcements, as these could come // We update inventories when receiving ref announcements, as these could come
// from a new repository being initialized. // from a new repository being initialized.
if let Ok(result) = if let Ok(result) =
@ -1428,7 +1433,7 @@ where
} }
// Update sync status of announcer for this repo. // Update sync status of announcer for this repo.
if let Some(refs) = message.refs.iter().find(|r| &r.remote == self.nid()) { if let Some(refs) = refs.iter().find(|r| &r.remote == self.nid()) {
debug!( debug!(
target: "service", target: "service",
"Refs announcement of {announcer} for {} contains our own remote at {} (t={})", "Refs announcement of {announcer} for {} contains our own remote at {} (t={})",
@ -1487,20 +1492,15 @@ where
); );
return Ok(relay); return Ok(relay);
}; };
// Finally, start the fetch.
// Finally, if there's anything to fetch, we fetch it from the remote. self.fetch_refs_at(
if let Some(refs) = NonEmpty::from_vec(message.refs.to_vec()) { message.rid,
self.fetch_refs_at( remote.id,
message.rid, refs,
remote.id, repo_entry.scope,
refs, FETCH_TIMEOUT,
repo_entry.scope, None,
FETCH_TIMEOUT, );
None,
);
} else {
debug!(target: "service", "Skipping fetch, no remote refs in announcement for {}", message.rid);
}
return Ok(relay); return Ok(relay);
} }
AnnouncementMessage::Node( AnnouncementMessage::Node(