redis_store: expire posts
This commit is contained in:
parent
9682ba2424
commit
7ad3accf82
|
@ -35,7 +35,7 @@ async fn main() {
|
|||
for host in config.hosts.into_iter() {
|
||||
scheduler.introduce(host);
|
||||
}
|
||||
|
||||
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(30))
|
||||
.user_agent(concat!(
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
use crate::feed::Post;
|
||||
|
||||
const POST_EXPIRE: usize = 86400;
|
||||
|
||||
pub async fn save_post(man: &mut redis::aio::ConnectionManager, host: &str, post: Post) -> bool {
|
||||
if redis::Cmd::getset(&format!("p:{}", post.url), "1")
|
||||
.query_async::<_, Option<Vec<u8>>>(man)
|
||||
.await.unwrap()
|
||||
.is_some() {
|
||||
// post is not new
|
||||
return false;
|
||||
}
|
||||
let post_key = format!("p:{}", post.url);
|
||||
let check = redis::pipe()
|
||||
.getset(&post_key, "1")
|
||||
.expire(post_key, POST_EXPIRE)
|
||||
.ignore()
|
||||
.query_async::<_, redis::Value>(man)
|
||||
.await
|
||||
.unwrap();
|
||||
if check != redis::Value::Bulk(vec![redis::Value::Nil]) {
|
||||
// post is not new
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(author_host) = post.account.host() {
|
||||
if author_host == host && post.url_host().map(|s| s == host).unwrap_or(false) {
|
||||
|
|
Loading…
Reference in New Issue