make posted return option, fix sorting
This commit is contained in:
parent
98239fd8f7
commit
9cc5307c59
1 changed files with 6 additions and 7 deletions
13
src/lib.rs
13
src/lib.rs
|
|
@ -22,7 +22,6 @@ const ZULIP_INTERVAL: Duration = Duration::from_millis(250);
|
|||
const ZULIP_MESSAGE_CUTOFF: usize = 700;
|
||||
|
||||
const LAST_FETCHED: DateTime<Utc> = DateTime::from_timestamp_nanos(0);
|
||||
const ONE_YEAR: Duration = Duration::from_secs(365 * 24 * 60 * 60);
|
||||
|
||||
pub struct BlogdorTheAggregator {
|
||||
db: SqlitePool,
|
||||
|
|
@ -252,12 +251,12 @@ impl BlogdorTheAggregator {
|
|||
}
|
||||
|
||||
trait Posted {
|
||||
fn posted(&self) -> DateTime<Utc>;
|
||||
fn posted(&self) -> Option<DateTime<Utc>>;
|
||||
}
|
||||
|
||||
impl Posted for feed_rs::model::Entry {
|
||||
fn posted(&self) -> DateTime<Utc> {
|
||||
self.published.or(self.updated).unwrap_or(LAST_FETCHED)
|
||||
fn posted(&self) -> Option<DateTime<Utc>> {
|
||||
self.published.or(self.updated)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -291,9 +290,9 @@ async fn check_feed(
|
|||
.map_err(|e| format!("could not get bytes from response from {url}, got {e}"))?;
|
||||
let mut feed =
|
||||
parse(feed.reader()).map_err(|e| format!("could not parse feed from {url}, got {e}"))?;
|
||||
feed.entries.sort_by_key(|e| e.posted());
|
||||
for post in feed.entries.into_iter().rev().take(5) {
|
||||
if post.posted() > last_fetched {
|
||||
feed.entries.sort_by_key(|e| std::cmp::Reverse(e.posted()));
|
||||
for post in feed.entries.into_iter().take(5) {
|
||||
if post.posted().unwrap_or(LAST_FETCHED) > last_fetched {
|
||||
let entry = FeedEntry {
|
||||
post_url: post
|
||||
.links
|
||||
|
|
|
|||
Loading…
Reference in a new issue