Store all relays in globals (ui will need for relay page)

This commit is contained in:
Mike Dilger 2022-12-24 20:52:23 +13:00
parent 28290a49b0
commit 84bac254b1
2 changed files with 17 additions and 1 deletions

View File

@ -44,6 +44,9 @@ pub struct Globals {
/// All nostr people records currently loaded into memory, keyed by pubkey
pub people: Mutex<HashMap<PublicKey, DbPerson>>,
/// All nostr relay records we have
pub relays: Mutex<HashMap<Url, DbRelay>>,
/// Whether or not we have a saved private key and need the password to unlock it
pub need_password: AtomicBool,
@ -74,6 +77,7 @@ lazy_static! {
last_reply: Mutex::new(HashMap::new()),
desired_events: Mutex::new(HashMap::new()),
people: Mutex::new(HashMap::new()),
relays: Mutex::new(HashMap::new()),
need_password: AtomicBool::new(false),
shutting_down: AtomicBool::new(false),
settings: Mutex::new(Settings::default()),

View File

@ -134,6 +134,18 @@ impl Overlord {
// updated from events without necessarily updating our relays list)
DbRelay::populate_new_relays().await?;
// Load relays from the database
let all_relays = DbRelay::fetch(None).await?;
// Store copy of all relays in globals (we use it again down below)
for relay in all_relays.iter() {
GLOBALS
.relays
.lock()
.await
.insert(Url(relay.url.clone()), relay.clone());
}
// Load people from the database
{
let mut dbpeople = DbPerson::fetch(None).await?;
@ -191,7 +203,7 @@ impl Overlord {
let pubkeys: Vec<PublicKeyHex> = crate::globals::followed_pubkeys().await;
let mut relay_picker = RelayPicker {
relays: DbRelay::fetch(None).await?,
relays: all_relays,
pubkeys: pubkeys.clone(),
person_relays: DbPersonRelay::fetch_for_pubkeys(&pubkeys).await?,
};