remove duplicate request
This commit is contained in:
@@ -1202,7 +1202,7 @@ impl Backend {
|
||||
let client = self.client.clone();
|
||||
|
||||
self.push_task(cx.spawn(async move |this, cx| {
|
||||
if let Err(e) = connect_repo_relays_only(&client, relays, filters).await {
|
||||
if let Err(e) = connect_repo_relays(&client, relays, filters).await {
|
||||
log::warn!("repo relay fetch failed: {e}");
|
||||
// Allow an immediate retry after a failure.
|
||||
this.update(cx, |this, _cx| {
|
||||
@@ -1433,54 +1433,27 @@ fn fetch_fingerprint(relays: &[&str], filters: &[Filter]) -> u64 {
|
||||
}
|
||||
|
||||
/// Add the given relays, connect and fetch the filters.
|
||||
async fn connect_repo_relays_only(
|
||||
async fn connect_repo_relays(
|
||||
client: &Client,
|
||||
relays: Vec<RelayUrl>,
|
||||
filters: Vec<Filter>,
|
||||
) -> Result<(), Error> {
|
||||
if relays.is_empty() {
|
||||
if relays.is_empty() || filters.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut added = false;
|
||||
for url in &relays {
|
||||
added |= client.add_relay(url).await?;
|
||||
// Ensure relay connections
|
||||
for url in relays.iter() {
|
||||
client.add_relay(url).await?;
|
||||
client.connect_relay(url).await?;
|
||||
}
|
||||
|
||||
// Connect only when the pool grew.
|
||||
if added {
|
||||
client.connect().await;
|
||||
}
|
||||
|
||||
let opts = SubscribeAutoCloseOptions::default()
|
||||
.exit_policy(ReqExitPolicy::ExitOnEOSE)
|
||||
.timeout(Some(Duration::from_secs(10)));
|
||||
|
||||
let target: HashMap<&str, Vec<Filter>> = relays
|
||||
.iter()
|
||||
.map(|url| (url.as_str(), filters.clone()))
|
||||
.collect();
|
||||
client.subscribe(target).close_on(opts).await?;
|
||||
|
||||
// Sync the filters concurrently.
|
||||
let sync_opts = SyncOptions::default().initial_timeout(Duration::from_secs(5));
|
||||
let syncs = filters.into_iter().map(|filter| {
|
||||
let client = &client;
|
||||
let relays = &relays;
|
||||
let sync_opts = sync_opts.clone();
|
||||
async move {
|
||||
if let Err(e) = client
|
||||
.sync(filter)
|
||||
.with(relays.iter())
|
||||
.opts(sync_opts)
|
||||
.await
|
||||
{
|
||||
// Run neg sync for each filter
|
||||
for filter in filters.into_iter() {
|
||||
if let Err(e) = client.sync(filter).with(relays.iter()).await {
|
||||
log::warn!("repo relay negentropy sync failed: {e}");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
futures::future::join_all(syncs).await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user