This commit is contained in:
Mike Dilger 2022-12-23 14:44:06 +13:00
parent 21c1619953
commit d8567da83a
4 changed files with 37 additions and 24 deletions

View File

@ -135,7 +135,11 @@ impl DbPerson {
Ok(()) Ok(())
} }
pub async fn update_metadata(pubkey: PublicKeyHex, metadata: Metadata, created_at: Unixtime) -> Result<(), Error> { pub async fn update_metadata(
pubkey: PublicKeyHex,
metadata: Metadata,
created_at: Unixtime,
) -> Result<(), Error> {
let sql = let sql =
"UPDATE person SET name=?, about=?, picture=?, dns_id=?, metadata_at=? WHERE pubkey=?"; "UPDATE person SET name=?, about=?, picture=?, dns_id=?, metadata_at=? WHERE pubkey=?";

View File

@ -134,19 +134,13 @@ pub async fn add_event(event: &Event) -> Result<(), Error> {
let count = event let count = event
.tags .tags
.iter() .iter()
.filter(|t| match t { .filter(|t| matches!(t, Tag::Event { .. }))
Tag::Event { .. } => true,
_ => false,
})
.count(); .count();
for (n, tag) in event for (n, tag) in event
.tags .tags
.iter() .iter()
.filter(|t| match t { .filter(|t| matches!(t, Tag::Event { .. }))
Tag::Event { .. } => true,
_ => false,
})
.enumerate() .enumerate()
{ {
if let Tag::Event { if let Tag::Event {
@ -232,7 +226,9 @@ pub async fn add_event(event: &Event) -> Result<(), Error> {
} }
// We ignore 'root' and 'refer'. // We ignore 'root' and 'refer'.
if let Some(id) = root { trace!("event root = {}", id.as_hex_string()); } if let Some(id) = root {
trace!("event root = {}", id.as_hex_string());
}
} }
// Some kinds seen in the wild: // Some kinds seen in the wild:
@ -361,7 +357,8 @@ pub async fn add_event(event: &Event) -> Result<(), Error> {
async fn insert_event(event: &Event) { async fn insert_event(event: &Event) {
let mut feed_events = GLOBALS.feed_events.lock().await; let mut feed_events = GLOBALS.feed_events.lock().await;
feed_events.entry(event.id) feed_events
.entry(event.id)
.and_modify(|feed_event| { .and_modify(|feed_event| {
// If the event already exists, update it's base data. // If the event already exists, update it's base data.
// (sometimes it is created to add feed data, but doesn't have base data yet) // (sometimes it is created to add feed data, but doesn't have base data yet)
@ -373,7 +370,7 @@ async fn insert_event(event: &Event) {
feed_event.event = Some(event.to_owned()); feed_event.event = Some(event.to_owned());
} }
}) })
.or_insert(event.into()); .or_insert_with(|| event.into());
} }
async fn update_feed_event<F>(id: Id, mut f: F) async fn update_feed_event<F>(id: Id, mut f: F)

View File

@ -8,7 +8,7 @@ use crate::error::Error;
use crate::globals::GLOBALS; use crate::globals::GLOBALS;
use crate::settings::Settings; use crate::settings::Settings;
use futures::{SinkExt, StreamExt}; use futures::{SinkExt, StreamExt};
use futures_util::stream::{SplitStream, SplitSink}; use futures_util::stream::{SplitSink, SplitStream};
use http::Uri; use http::Uri;
use nostr_proto::{EventKind, Filters, PublicKeyHex, RelayInformationDocument, Unixtime, Url}; use nostr_proto::{EventKind, Filters, PublicKeyHex, RelayInformationDocument, Unixtime, Url};
use subscription::Subscriptions; use subscription::Subscriptions;

View File

@ -113,20 +113,29 @@ impl Overlord {
let metadata: Metadata = match serde_json::from_str(&dbevent.content) { let metadata: Metadata = match serde_json::from_str(&dbevent.content) {
Ok(e) => e, Ok(e) => e,
Err(_) => { Err(_) => {
error!("Bad metadata: id={}, content={}", dbevent.id, dbevent.content); error!(
"Bad metadata: id={}, content={}",
dbevent.id, dbevent.content
);
continue; continue;
} }
}; };
// Update in globals // Update in globals
crate::globals::update_person_from_event_metadata( crate::globals::update_person_from_event_metadata(
e.pubkey, e.created_at, metadata.clone() e.pubkey,
).await; e.created_at,
metadata.clone(),
)
.await;
// Update in database // Update in database
DbPerson::update_metadata(PublicKeyHex(e.pubkey.as_hex_string()), DbPerson::update_metadata(
PublicKeyHex(e.pubkey.as_hex_string()),
metadata, metadata,
e.created_at).await?; e.created_at,
)
.await?;
} }
} }
@ -272,7 +281,10 @@ impl Overlord {
debug!("new feed event arrived: {}...", event.id.as_hex_string()); debug!("new feed event arrived: {}...", event.id.as_hex_string());
} else { } else {
// Not Feed Related: Metadata, RecommendRelay, ContactList // Not Feed Related: Metadata, RecommendRelay, ContactList
debug!("new non-feed event arrived: {}...", event.id.as_hex_string()); debug!(
"new non-feed event arrived: {}...",
event.id.as_hex_string()
);
if event.kind == EventKind::Metadata { if event.kind == EventKind::Metadata {
let metadata: Metadata = serde_json::from_str(&event.content)?; let metadata: Metadata = serde_json::from_str(&event.content)?;