mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
get_missing_events button on feed
This commit is contained in:
parent
4f57ad26f5
commit
a86776f5f2
@ -138,15 +138,25 @@ impl Globals {
|
|||||||
.or_insert_with(|| if let Some(u) = url { vec![u] } else { vec![] });
|
.or_insert_with(|| if let Some(u) = url { vec![u] } else { vec![] });
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_desired_events_prelude() -> Result<(), Error> {
|
pub fn trim_desired_events_sync() {
|
||||||
// Strip out Ids of events that we already have
|
|
||||||
{
|
|
||||||
// danger - two locks could lead to deadlock, check other code locking these
|
// danger - two locks could lead to deadlock, check other code locking these
|
||||||
|
// don't change the order, or else change it everywhere
|
||||||
|
let mut desired_events = GLOBALS.desired_events.blocking_lock();
|
||||||
|
let events = GLOBALS.events.blocking_lock();
|
||||||
|
desired_events.retain(|&id, _| !events.contains_key(&id));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn trim_desired_events() {
|
||||||
|
// danger - two locks could lead to deadlock, check other code locking these
|
||||||
|
// don't change the order, or else change it everywhere
|
||||||
let mut desired_events = GLOBALS.desired_events.lock().await;
|
let mut desired_events = GLOBALS.desired_events.lock().await;
|
||||||
let events = GLOBALS.events.lock().await;
|
let events = GLOBALS.events.lock().await;
|
||||||
desired_events.retain(|&id, _| !events.contains_key(&id));
|
desired_events.retain(|&id, _| !events.contains_key(&id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_desired_events_prelude() -> Result<(), Error> {
|
||||||
|
Self::trim_desired_events().await;
|
||||||
|
|
||||||
// Load from database
|
// Load from database
|
||||||
{
|
{
|
||||||
let ids: Vec<IdHex> = GLOBALS
|
let ids: Vec<IdHex> = GLOBALS
|
||||||
@ -170,13 +180,7 @@ impl Globals {
|
|||||||
info!("Loaded {} desired events from the database", count);
|
info!("Loaded {} desired events from the database", count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip out Ids of events that we already have (again, we just loaded from db)
|
Self::trim_desired_events().await; // again
|
||||||
{
|
|
||||||
// danger - two locks could lead to deadlock, check other code locking these
|
|
||||||
let mut desired_events = GLOBALS.desired_events.lock().await;
|
|
||||||
let events = GLOBALS.events.lock().await;
|
|
||||||
desired_events.retain(|&id, _| !events.contains_key(&id));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -213,32 +213,7 @@ impl Overlord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get desired events from relays
|
// Get desired events from relays
|
||||||
{
|
self.get_missing_events().await?;
|
||||||
let (desired_events_map, desired_events_vec) = Globals::get_desired_events().await?;
|
|
||||||
|
|
||||||
info!(
|
|
||||||
"Seeking {} events",
|
|
||||||
desired_events_map.len() + desired_events_vec.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
for (url, mut ids) in desired_events_map {
|
|
||||||
// Add the orphans
|
|
||||||
ids.extend(&desired_events_vec);
|
|
||||||
|
|
||||||
// If we don't have such a minion, start one
|
|
||||||
if !self.urls_watching.contains(&url) {
|
|
||||||
// Start a minion
|
|
||||||
self.start_minion(url.0.clone()).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tell it to get these events
|
|
||||||
let _ = self.to_minions.send(BusMessage {
|
|
||||||
target: url.0.clone(),
|
|
||||||
kind: "fetch_events".to_string(),
|
|
||||||
json_payload: serde_json::to_string(&ids).unwrap(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
'mainloop: loop {
|
'mainloop: loop {
|
||||||
match self.loop_handler().await {
|
match self.loop_handler().await {
|
||||||
@ -371,6 +346,9 @@ impl Overlord {
|
|||||||
|
|
||||||
debug!("Settings saved.");
|
debug!("Settings saved.");
|
||||||
}
|
}
|
||||||
|
"get_missing_events" => {
|
||||||
|
self.get_missing_events().await?;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -378,4 +356,33 @@ impl Overlord {
|
|||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_missing_events(&mut self) -> Result<(), Error> {
|
||||||
|
let (desired_events_map, desired_events_vec) = Globals::get_desired_events().await?;
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"Seeking {} events",
|
||||||
|
desired_events_map.len() + desired_events_vec.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
for (url, mut ids) in desired_events_map {
|
||||||
|
// Add the orphans
|
||||||
|
ids.extend(&desired_events_vec);
|
||||||
|
|
||||||
|
// If we don't have such a minion, start one
|
||||||
|
if !self.urls_watching.contains(&url) {
|
||||||
|
// Start a minion
|
||||||
|
self.start_minion(url.0.clone()).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tell it to get these events
|
||||||
|
let _ = self.to_minions.send(BusMessage {
|
||||||
|
target: url.0.clone(),
|
||||||
|
kind: "fetch_events".to_string(),
|
||||||
|
json_payload: serde_json::to_string(&ids).unwrap(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use super::GossipUi;
|
use super::GossipUi;
|
||||||
|
use crate::comms::BusMessage;
|
||||||
use crate::globals::{Globals, GLOBALS};
|
use crate::globals::{Globals, GLOBALS};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use egui::{Align, Color32, Context, Layout, RichText, ScrollArea, TextStyle, Ui, Vec2};
|
use egui::{Align, Color32, Context, Layout, RichText, ScrollArea, TextStyle, Ui, Vec2};
|
||||||
@ -10,6 +11,11 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
|
|||||||
|
|
||||||
//let screen_rect = ctx.input().screen_rect; // Rect
|
//let screen_rect = ctx.input().screen_rect; // Rect
|
||||||
|
|
||||||
|
let desired_count = {
|
||||||
|
Globals::trim_desired_events_sync();
|
||||||
|
GLOBALS.desired_events.blocking_lock().len()
|
||||||
|
};
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.text_edit_multiline(&mut app.draft);
|
ui.text_edit_multiline(&mut app.draft);
|
||||||
|
|
||||||
@ -23,6 +29,20 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
|
|||||||
|
|
||||||
app.draft = "".to_owned();
|
app.draft = "".to_owned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.with_layout(Layout::right_to_left(Align::TOP), |ui| {
|
||||||
|
ui.with_layout(Layout::top_down(Align::Max), |ui| {
|
||||||
|
ui.label(&format!("{} missing events", desired_count));
|
||||||
|
if ui.button("Get 'em").clicked() {
|
||||||
|
let tx = GLOBALS.to_overlord.clone();
|
||||||
|
let _ = tx.send(BusMessage {
|
||||||
|
target: "overlord".to_string(),
|
||||||
|
kind: "get_missing_events".to_string(),
|
||||||
|
json_payload: serde_json::to_string("").unwrap(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ScrollArea::vertical().show(ui, |ui| {
|
ScrollArea::vertical().show(ui, |ui| {
|
||||||
|
Loading…
Reference in New Issue
Block a user