Add logging to cache misses

This commit is contained in:
asonix 2020-03-25 17:34:54 -05:00
parent 78a359c403
commit b7f2de0245

View file

@ -1,7 +1,7 @@
use crate::{db::Db, error::MyError}; use crate::{db::Db, error::MyError};
use activitystreams::primitives::XsdAnyUri; use activitystreams::primitives::XsdAnyUri;
use bb8_postgres::tokio_postgres::types::Json; use bb8_postgres::tokio_postgres::types::Json;
use log::error; use log::{error, info};
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
sync::Arc, sync::Arc,
@ -63,13 +63,19 @@ impl NodeCache {
let read_guard = self.nodes.read().await; let read_guard = self.nodes.read().await;
let node = match read_guard.get(listener) { let node = match read_guard.get(listener) {
None => return true, None => {
info!("No node for listener {}", listener);
return true;
}
Some(node) => node, Some(node) => node,
}; };
match node.contact.as_ref() { match node.contact.as_ref() {
Some(contact) => contact.outdated(), Some(contact) => contact.outdated(),
None => true, None => {
info!("No contact for node {}", node.base);
true
}
} }
} }
@ -77,13 +83,19 @@ impl NodeCache {
let read_guard = self.nodes.read().await; let read_guard = self.nodes.read().await;
let node = match read_guard.get(listener) { let node = match read_guard.get(listener) {
None => return true, None => {
info!("No node for listener {}", listener);
return true;
}
Some(node) => node, Some(node) => node,
}; };
match node.instance.as_ref() { match node.instance.as_ref() {
Some(instance) => instance.outdated(), Some(instance) => instance.outdated(),
None => true, None => {
info!("No instance for node {}", node.base);
true
}
} }
} }
@ -190,7 +202,7 @@ impl NodeCache {
.entry(listener.clone()) .entry(listener.clone())
.or_insert(Node::new(listener.clone())); .or_insert(Node::new(listener.clone()));
node.set_info(software, version, reg); node.set_info(software, version, reg);
self.save(listener, &*node).await?; self.save(listener, node).await?;
Ok(()) Ok(())
} }
@ -214,7 +226,7 @@ impl NodeCache {
.entry(listener.clone()) .entry(listener.clone())
.or_insert(Node::new(listener.clone())); .or_insert(Node::new(listener.clone()));
node.set_instance(title, description, version, reg, requires_approval); node.set_instance(title, description, version, reg, requires_approval);
self.save(listener, &*node).await?; self.save(listener, node).await?;
Ok(()) Ok(())
} }
@ -237,7 +249,7 @@ impl NodeCache {
.entry(listener.clone()) .entry(listener.clone())
.or_insert(Node::new(listener.clone())); .or_insert(Node::new(listener.clone()));
node.set_contact(username, display_name, url, avatar); node.set_contact(username, display_name, url, avatar);
self.save(listener, &*node).await?; self.save(listener, node).await?;
Ok(()) Ok(())
} }