mirror of
https://git.alemi.dev/fedicharter.git
synced 2024-11-22 16:34:49 +01:00
fix: also cache instances without metadata
This commit is contained in:
parent
eb32729b15
commit
0a3b4781cc
2 changed files with 13 additions and 6 deletions
13
src/cache.rs
13
src/cache.rs
|
@ -11,11 +11,11 @@ const MAX_CACHE_AGE : i64 = 86400;
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct InstanceCache {
|
||||
store: RwLock<HashMap<String, (i64, serde_json::Value)>>,
|
||||
store: RwLock<HashMap<String, (i64, Option<serde_json::Value>)>>,
|
||||
}
|
||||
|
||||
impl InstanceCache {
|
||||
pub async fn instance_metadata(&self, domain: &str) -> reqwest::Result<serde_json::Value> {
|
||||
pub async fn instance_metadata(&self, domain: &str) -> reqwest::Result<Option<serde_json::Value>> {
|
||||
let now = Utc::now().timestamp();
|
||||
|
||||
if let Some((age, value)) = self.store.read().await.get(domain) {
|
||||
|
@ -24,15 +24,18 @@ impl InstanceCache {
|
|||
}
|
||||
}
|
||||
|
||||
let value = reqwest::Client::builder()
|
||||
let response = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(5))
|
||||
.build()?
|
||||
.get(format!("https://{}/nodeinfo/2.0.json", domain))
|
||||
.send()
|
||||
.await?
|
||||
.json::<serde_json::Value>()
|
||||
.await?;
|
||||
|
||||
let value = response
|
||||
.json::<serde_json::Value>()
|
||||
.await
|
||||
.ok();
|
||||
|
||||
self.store.write().await.insert(domain.to_string(), (now, value.clone()));
|
||||
|
||||
Ok(value)
|
||||
|
|
|
@ -68,7 +68,11 @@ async fn scan_instance(domain: &str, map: Arc<Mutex<Map>>) -> Option<()> {
|
|||
|
||||
tracing::debug!("scanning instance {}", domain);
|
||||
let response = match CACHE.instance_metadata(domain).await {
|
||||
Ok(r) => r,
|
||||
Ok(Some(r)) => r,
|
||||
Ok(None) => {
|
||||
tracing::info!("instance {} doesn't provide metadata", domain);
|
||||
return None
|
||||
},
|
||||
Err(e) => {
|
||||
tracing::warn!("could not fetch metadata for {}: {}", domain, e);
|
||||
return None
|
||||
|
|
Loading…
Reference in a new issue