trends: check if new, also store by instance

This commit is contained in:
Astro 2022-11-03 02:54:56 +01:00
parent f9e3f1e452
commit 91c00e8027

View File

@ -13,12 +13,17 @@ pub async fn spawn(redis_url: &str, mut post_rx: tokio::sync::mpsc::UnboundedRec
} }
if let Some(timestamp) = post.timestamp() { if let Some(timestamp) = post.timestamp() {
let post_key = format!("p:{}", post.url); if redis::Cmd::getset(&format!("p:{}", post.url), "1")
let cmd = redis::Cmd::getset(&post_key, "1"); .query_async::<_, Option<Vec<u8>>>(&mut man)
if cmd.query_async::<_, Option<Vec<u8>>>(&mut man).await.unwrap().is_some() { .await.unwrap()
continue; .is_some() {
} continue;
}
let host = match post.url_host() {
Some(host) => host,
None => continue,
};
let hour = timestamp.naive_utc().timestamp() / 3600; let hour = timestamp.naive_utc().timestamp() / 3600;
let mut cmd = redis::pipe(); let mut cmd = redis::pipe();
for tag in post.tags { for tag in post.tags {
@ -26,15 +31,21 @@ pub async fn spawn(redis_url: &str, mut post_rx: tokio::sync::mpsc::UnboundedRec
// by hour // by hour
cmd.hincr( cmd.hincr(
&tag_key, &tag_key,
format!("h:{}", hour), format!("t:{}", hour),
1 1
).ignore(); ).ignore();
// by spelling // by spelling
cmd.hincr( cmd.hincr(
tag_key, &tag_key,
format!("s:{}", tag.name), format!("s:{}", tag.name),
1 1
).ignore(); ).ignore();
// by instance
cmd.hincr(
tag_key,
format!("h:{}", host),
1
).ignore();
} }
match cmd.query_async(&mut man).await { match cmd.query_async(&mut man).await {
Ok(()) => {} Ok(()) => {}