trends: check if new, also store by instance
This commit is contained in:
parent
f9e3f1e452
commit
91c00e8027
|
@ -13,12 +13,17 @@ pub async fn spawn(redis_url: &str, mut post_rx: tokio::sync::mpsc::UnboundedRec
|
|||
}
|
||||
|
||||
if let Some(timestamp) = post.timestamp() {
|
||||
let post_key = format!("p:{}", post.url);
|
||||
let cmd = redis::Cmd::getset(&post_key, "1");
|
||||
if cmd.query_async::<_, Option<Vec<u8>>>(&mut man).await.unwrap().is_some() {
|
||||
continue;
|
||||
}
|
||||
if redis::Cmd::getset(&format!("p:{}", post.url), "1")
|
||||
.query_async::<_, Option<Vec<u8>>>(&mut man)
|
||||
.await.unwrap()
|
||||
.is_some() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let host = match post.url_host() {
|
||||
Some(host) => host,
|
||||
None => continue,
|
||||
};
|
||||
let hour = timestamp.naive_utc().timestamp() / 3600;
|
||||
let mut cmd = redis::pipe();
|
||||
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
|
||||
cmd.hincr(
|
||||
&tag_key,
|
||||
format!("h:{}", hour),
|
||||
format!("t:{}", hour),
|
||||
1
|
||||
).ignore();
|
||||
// by spelling
|
||||
cmd.hincr(
|
||||
tag_key,
|
||||
&tag_key,
|
||||
format!("s:{}", tag.name),
|
||||
1
|
||||
).ignore();
|
||||
// by instance
|
||||
cmd.hincr(
|
||||
tag_key,
|
||||
format!("h:{}", host),
|
||||
1
|
||||
).ignore();
|
||||
}
|
||||
match cmd.query_async(&mut man).await {
|
||||
Ok(()) => {}
|
||||
|
|
Loading…
Reference in New Issue