Fix overlord's wrong usage of default settings

This commit is contained in:
Mike Dilger 2022-12-27 17:01:00 +13:00
parent daac5124bf
commit 1c377e058a
2 changed files with 12 additions and 18 deletions

View File

@ -218,14 +218,13 @@ impl Minion {
}, },
Err(e) => return Err(e.into()) Err(e) => return Err(e.into())
}; };
#[allow(clippy::collapsible_if)]
if bus_message.target == self.url.0 { if bus_message.target == self.url.0 {
self.handle_bus_message(bus_message).await?; self.handle_bus_message(bus_message).await?;
} else if &*bus_message.target == "all" { } else if &*bus_message.target == "all" {
if &*bus_message.kind == "shutdown" { if &*bus_message.kind == "shutdown" {
info!("{}: Websocket listener shutting down", &self.url); info!("{}: Websocket listener shutting down", &self.url);
keepgoing = false; keepgoing = false;
} else if &*bus_message.kind == "settings_changed" {
// TBD: possibly redo filters based on overlap, feed_chunk, etc.
} }
} }
}, },
@ -269,14 +268,17 @@ impl Minion {
let mut special_since: i64 = let mut special_since: i64 =
DbPersonRelay::fetch_oldest_last_fetched(&pubkeys, &self.url.0).await? as i64; DbPersonRelay::fetch_oldest_last_fetched(&pubkeys, &self.url.0).await? as i64;
let (overlap, feed_chunk) = {
let settings = GLOBALS.settings.lock().await.clone(); let settings = GLOBALS.settings.lock().await.clone();
(settings.overlap, settings.feed_chunk)
};
// Subtract overlap to avoid gaps due to clock sync and event // Subtract overlap to avoid gaps due to clock sync and event
// propogation delay // propogation delay
special_since -= settings.overlap as i64; special_since -= overlap as i64;
// For feed related events, don't look back more than one feed_chunk ago // For feed related events, don't look back more than one feed_chunk ago
let one_feedchunk_ago = Unixtime::now().unwrap().0 - settings.feed_chunk as i64; let one_feedchunk_ago = Unixtime::now().unwrap().0 - feed_chunk as i64;
let feed_since = special_since.max(one_feedchunk_ago); let feed_since = special_since.max(one_feedchunk_ago);
(Unixtime(feed_since), Unixtime(special_since)) (Unixtime(feed_since), Unixtime(special_since))

View File

@ -16,7 +16,6 @@ use tokio::{select, task};
use tracing::{debug, error, info, warn}; use tracing::{debug, error, info, warn};
pub struct Overlord { pub struct Overlord {
settings: Settings,
to_minions: Sender<BusMessage>, to_minions: Sender<BusMessage>,
from_minions: UnboundedReceiver<BusMessage>, from_minions: UnboundedReceiver<BusMessage>,
@ -37,7 +36,6 @@ impl Overlord {
pub fn new(from_minions: UnboundedReceiver<BusMessage>) -> Overlord { pub fn new(from_minions: UnboundedReceiver<BusMessage>) -> Overlord {
let to_minions = GLOBALS.to_minions.clone(); let to_minions = GLOBALS.to_minions.clone();
Overlord { Overlord {
settings: Settings::default(),
to_minions, to_minions,
from_minions, from_minions,
minions: task::JoinSet::new(), minions: task::JoinSet::new(),
@ -98,7 +96,9 @@ impl Overlord {
// FIXME - if this needs doing, it should be done dynamically as // FIXME - if this needs doing, it should be done dynamically as
// new people are encountered, not batch-style on startup. // new people are encountered, not batch-style on startup.
// Create a person record for every person seen, possibly autofollow // Create a person record for every person seen, possibly autofollow
DbPerson::populate_new_people(self.settings.autofollow).await?;
let autofollow = GLOBALS.settings.lock().await.autofollow;
DbPerson::populate_new_people(autofollow).await?;
// FIXME - if this needs doing, it should be done dynamically as // FIXME - if this needs doing, it should be done dynamically as
// new people are encountered, not batch-style on startup. // new people are encountered, not batch-style on startup.
@ -147,7 +147,8 @@ impl Overlord {
// Load feed-related events from database and process (TextNote, EventDeletion, Reaction) // Load feed-related events from database and process (TextNote, EventDeletion, Reaction)
{ {
let now = Unixtime::now().unwrap(); let now = Unixtime::now().unwrap();
let then = now.0 - self.settings.feed_chunk as i64; let feed_chunk = GLOBALS.settings.lock().await.feed_chunk;
let then = now.0 - feed_chunk as i64;
let db_events = DbEvent::fetch(Some(&format!( let db_events = DbEvent::fetch(Some(&format!(
" (kind=1 OR kind=5 OR kind=7) AND created_at > {} ORDER BY created_at ASC", " (kind=1 OR kind=5 OR kind=7) AND created_at > {} ORDER BY created_at ASC",
then then
@ -321,15 +322,6 @@ impl Overlord {
info!("Overlord shutting down"); info!("Overlord shutting down");
return Ok(false); return Ok(false);
} }
"settings_changed" => {
self.settings = serde_json::from_str(&bus_message.json_payload)?;
// We need to inform the minions
self.to_minions.send(BusMessage {
target: "all".to_string(),
kind: "settings_changed".to_string(),
json_payload: bus_message.json_payload.clone(),
})?;
}
_ => {} _ => {}
}, },
"overlord" => match &*bus_message.kind { "overlord" => match &*bus_message.kind {