mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
On relay success, update relay table, not person_relay last_fetched
This commit is contained in:
parent
d693907cf4
commit
67859ef9e5
@ -164,22 +164,6 @@ impl DbPersonRelay {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_last_fetched(relay: String, last_fetched: u64) -> Result<(), Error> {
|
|
||||||
let sql = "UPDATE person_relay SET last_fetched=? where relay=?";
|
|
||||||
|
|
||||||
spawn_blocking(move || {
|
|
||||||
let maybe_db = GLOBALS.db.blocking_lock();
|
|
||||||
let db = maybe_db.as_ref().unwrap();
|
|
||||||
|
|
||||||
let mut stmt = db.prepare(sql)?;
|
|
||||||
stmt.execute((&last_fetched, &*relay))?;
|
|
||||||
Ok::<(), Error>(())
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub async fn delete(criteria: &str) -> Result<(), Error> {
|
pub async fn delete(criteria: &str) -> Result<(), Error> {
|
||||||
let sql = format!("DELETE FROM person_relay WHERE {}", criteria);
|
let sql = format!("DELETE FROM person_relay WHERE {}", criteria);
|
||||||
|
@ -107,6 +107,24 @@ impl DbRelay {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This also bumps success_count
|
||||||
|
pub async fn update_success(url: String, last_success_at: u64) -> Result<(), Error> {
|
||||||
|
let sql = "UPDATE relay SET success_count = success_count + 1, last_success_at = ? \
|
||||||
|
WHERE url = ?";
|
||||||
|
|
||||||
|
spawn_blocking(move || {
|
||||||
|
let maybe_db = GLOBALS.db.blocking_lock();
|
||||||
|
let db = maybe_db.as_ref().unwrap();
|
||||||
|
|
||||||
|
let mut stmt = db.prepare(sql)?;
|
||||||
|
stmt.execute((&last_success_at, &url))?;
|
||||||
|
Ok::<(), Error>(())
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub async fn delete(criteria: &str) -> Result<(), Error> {
|
pub async fn delete(criteria: &str) -> Result<(), Error> {
|
||||||
let sql = format!("DELETE FROM relay WHERE {}", criteria);
|
let sql = format!("DELETE FROM relay WHERE {}", criteria);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use super::Minion;
|
use super::Minion;
|
||||||
use crate::db::DbPersonRelay;
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use nostr_types::{RelayMessage, Unixtime};
|
use nostr_types::{RelayMessage, Unixtime};
|
||||||
use tracing::{debug, error, info, warn};
|
use tracing::{debug, error, info, warn};
|
||||||
@ -27,10 +26,6 @@ impl Minion {
|
|||||||
info!("NOTICE: {} {}", &self.url, msg);
|
info!("NOTICE: {} {}", &self.url, msg);
|
||||||
}
|
}
|
||||||
RelayMessage::Eose(subid) => {
|
RelayMessage::Eose(subid) => {
|
||||||
// We should update last_fetched
|
|
||||||
let now = Unixtime::now().unwrap().0 as u64;
|
|
||||||
DbPersonRelay::update_last_fetched(self.url.0.clone(), now).await?;
|
|
||||||
|
|
||||||
// Update the matching subscription
|
// Update the matching subscription
|
||||||
match self.subscriptions.get_mut_by_id(&subid.0) {
|
match self.subscriptions.get_mut_by_id(&subid.0) {
|
||||||
Some(sub) => {
|
Some(sub) => {
|
||||||
|
@ -140,8 +140,8 @@ impl Minion {
|
|||||||
|
|
||||||
// Bump the success count for the relay
|
// Bump the success count for the relay
|
||||||
{
|
{
|
||||||
self.dbrelay.success_count += 1;
|
let now = Unixtime::now().unwrap().0 as u64;
|
||||||
DbRelay::update(self.dbrelay.clone()).await?;
|
DbRelay::update_success(self.dbrelay.url.clone(), now).await?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe to the people we follow
|
// Subscribe to the people we follow
|
||||||
|
@ -10,8 +10,8 @@ pub(super) fn update(_app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::F
|
|||||||
ui.add_space(18.0);
|
ui.add_space(18.0);
|
||||||
|
|
||||||
let mut relays = GLOBALS.relays.blocking_lock().clone();
|
let mut relays = GLOBALS.relays.blocking_lock().clone();
|
||||||
let mut relays: Vec<DbRelay> = relays.drain().map(|(_,relay)| relay).collect();
|
let mut relays: Vec<DbRelay> = relays.drain().map(|(_, relay)| relay).collect();
|
||||||
relays.sort_by(|a,b| a.url.cmp(&b.url));
|
relays.sort_by(|a, b| a.url.cmp(&b.url));
|
||||||
|
|
||||||
ScrollArea::vertical().show(ui, |ui| {
|
ScrollArea::vertical().show(ui, |ui| {
|
||||||
for relay in relays.iter() {
|
for relay in relays.iter() {
|
||||||
|
Loading…
Reference in New Issue
Block a user