hunter/redis_store: ignore future or ancient posts
This commit is contained in:
parent
02f047d469
commit
6ac923f270
|
@ -1,6 +1,7 @@
|
|||
use crate::feed::{Post, Tag};
|
||||
|
||||
const POST_EXPIRE: usize = 86400;
|
||||
const TAG_EXPIRE: i64 = 30 * 24;
|
||||
|
||||
// TODO: make state obj w/ ConnectionManager
|
||||
pub async fn save_post(man: &mut redis::aio::ConnectionManager, post: Post) -> bool {
|
||||
|
@ -48,6 +49,16 @@ async fn save_post_tags(man: &mut redis::aio::ConnectionManager, post: Post) {
|
|||
}
|
||||
};
|
||||
let hour = timestamp.naive_utc().timestamp() / 3600;
|
||||
let until = chrono::offset::Utc::now().naive_utc().timestamp() / 3600;
|
||||
if hour > until {
|
||||
log::warn!("future post from {}", timestamp);
|
||||
return;
|
||||
}
|
||||
let from = until - TAG_EXPIRE;
|
||||
if hour < from {
|
||||
log::warn!("ancient post from {}", timestamp);
|
||||
return;
|
||||
}
|
||||
|
||||
let mut cmd = redis::pipe();
|
||||
let mut store_tags = |tag: &Tag, tag_key| {
|
||||
|
|
Loading…
Reference in New Issue
Block a user