Addressing PR comments

upgrade_deps_20
Dessalines 2024-03-15 08:40:27 -04:00
parent 85124fc39a
commit 12a549ce6a
3 changed files with 5 additions and 10 deletions

View File

@ -27,7 +27,7 @@ use crate::{
}, },
}; };
use ::url::Url; use ::url::Url;
use chrono::{TimeDelta, Utc}; use chrono::Utc;
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods}; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use std::collections::HashSet; use std::collections::HashSet;
@ -105,12 +105,7 @@ impl Post {
.filter(post::deleted.eq(false)) .filter(post::deleted.eq(false))
.filter(post::removed.eq(false)) .filter(post::removed.eq(false))
.filter( .filter(
post::published.ge( post::published.ge(Utc::now().naive_utc() - SITEMAP_DAYS.expect("TimeDelta out of bounds")),
Utc::now().naive_utc()
- TimeDelta::try_days(SITEMAP_DAYS)
.ok_or("TimeDelta out of bounds")
.map_err(|e| Error::QueryBuilderError(e.into()))?,
),
) )
.order(post::published.desc()) .order(post::published.desc())
.limit(SITEMAP_LIMIT) .limit(SITEMAP_LIMIT)

View File

@ -6,7 +6,7 @@ use crate::{
SortType, SortType,
}; };
use anyhow::Context; use anyhow::Context;
use chrono::{DateTime, Utc}; use chrono::{DateTime, TimeDelta, Utc};
use deadpool::Runtime; use deadpool::Runtime;
use diesel::{ use diesel::{
helper_types::AsExprOf, helper_types::AsExprOf,
@ -51,7 +51,7 @@ use url::Url;
const FETCH_LIMIT_DEFAULT: i64 = 10; const FETCH_LIMIT_DEFAULT: i64 = 10;
pub const FETCH_LIMIT_MAX: i64 = 50; pub const FETCH_LIMIT_MAX: i64 = 50;
pub const SITEMAP_LIMIT: i64 = 50000; pub const SITEMAP_LIMIT: i64 = 50000;
pub const SITEMAP_DAYS: i64 = 31; pub const SITEMAP_DAYS: Option<TimeDelta> = TimeDelta::try_days(31);
pub const RANK_DEFAULT: f64 = 0.0001; pub const RANK_DEFAULT: f64 = 0.0001;
pub type ActualDbPool = Pool<AsyncPgConnection>; pub type ActualDbPool = Pool<AsyncPgConnection>;

View File

@ -333,7 +333,7 @@ impl InstanceWorker {
last_fetch: DateTime<Utc>, last_fetch: DateTime<Utc>,
) -> Result<(HashMap<CommunityId, HashSet<Url>>, DateTime<Utc>)> { ) -> Result<(HashMap<CommunityId, HashSet<Url>>, DateTime<Utc>)> {
let new_last_fetch = let new_last_fetch =
Utc::now() - chrono::TimeDelta::try_seconds(10).context("TimeDelta out of bounds")?; // update to time before fetch to ensure overlap. subtract 10s to ensure overlap even if published date is not exact Utc::now() - chrono::TimeDelta::try_seconds(10).expect("TimeDelta out of bounds"); // update to time before fetch to ensure overlap. subtract 10s to ensure overlap even if published date is not exact
Ok(( Ok((
CommunityFollowerView::get_instance_followed_community_inboxes(pool, instance_id, last_fetch) CommunityFollowerView::get_instance_followed_community_inboxes(pool, instance_id, last_fetch)
.await? .await?