From add7c9930354db35c995bfd5baf8eaf76e3da52c Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Wed, 26 Jul 2023 07:49:10 +1200 Subject: [PATCH] Load last contact list data at startup so we have data on the people-followed page --- src/people.rs | 32 ++++++++++++++++++++++++++++++-- src/storage/import/mod.rs | 6 ++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/people.rs b/src/people.rs index 5ab57a57..b8247043 100644 --- a/src/people.rs +++ b/src/people.rs @@ -147,6 +147,33 @@ impl People { // Start the periodic task management pub fn start() { + // Load our contact list from the database in order to populate + // last_contact_list_asof and last_contact_list_size + if let Some(pk) = GLOBALS.signer.public_key() { + if let Ok(Some(event)) = GLOBALS.storage.fetch_contact_list(&pk) { + if event.created_at.0 + > GLOBALS + .people + .last_contact_list_asof + .load(Ordering::Relaxed) + { + GLOBALS + .people + .last_contact_list_asof + .store(event.created_at.0, Ordering::Relaxed); + let size = event + .tags + .iter() + .filter(|t| matches!(t, Tag::Pubkey { .. })) + .count(); + GLOBALS + .people + .last_contact_list_size + .store(size, Ordering::Relaxed); + } + } + } + task::spawn(async { loop { // Every 3 seconds... @@ -178,8 +205,9 @@ impl People { let one_day_ago = Unixtime::now().unwrap().0 - (60 * 60 * 8); if let Ok(vec) = GLOBALS.storage.filter_people(|p| { - p.followed && - p.relay_list_last_received < one_day_ago && among_these.contains(&p.pubkey) + p.followed + && p.relay_list_last_received < one_day_ago + && among_these.contains(&p.pubkey) }) { vec.iter().map(|p| p.pubkey).collect() } else { diff --git a/src/storage/import/mod.rs b/src/storage/import/mod.rs index 1535c8b0..96328be9 100644 --- a/src/storage/import/mod.rs +++ b/src/storage/import/mod.rs @@ -151,9 +151,11 @@ where settings.recompute_feed_periodically = numstr_to_bool(value) } "feed_recompute_interval_ms" => { - if let Ok(x) = value.parse::() { + if let Ok(mut x) = value.parse::() { // Force longer intervals for currently slower LMDB: - if x<5000 { x = 5000; } + if x < 5000 { + x = 5000; + } settings.feed_recompute_interval_ms = x; }