Extend sitemap span (#4231)

* Extend sitemap span

* Keep cargo_fmt happy

* Add FETCH_LIMIT_SITEMAP

* Use FETCH_LIMIT_SITEMAP

* Keep cargo_fmt happy

* Update utils.rs

* Use SITEMAP_DAYS

* Keep cargo_fmt happy

* Sitemap

* Keep cargo_fmt happy

* Sitemap

* Sitemap

* Increase to 31 days
This commit is contained in:
Kroese 2023-12-11 11:24:51 +01:00 committed by GitHub
parent c85e680aba
commit 2d4037ba61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View file

@ -26,7 +26,7 @@ async fn generate_urlset(
}
pub async fn get_sitemap(context: Data<LemmyContext>) -> LemmyResult<HttpResponse> {
info!("Generating sitemap with posts from last {} hours...", 24);
info!("Generating sitemap...",);
let posts = Post::list_for_sitemap(&mut context.pool()).await?;
info!("Loaded latest {} posts", posts.len());
@ -36,7 +36,7 @@ pub async fn get_sitemap(context: Data<LemmyContext>) -> LemmyResult<HttpRespons
Ok(
HttpResponse::Ok()
.content_type("application/xml")
.insert_header(header::CacheControl(vec![CacheDirective::MaxAge(86_400)])) // 24 h
.insert_header(header::CacheControl(vec![CacheDirective::MaxAge(3_600)])) // 1 h
.body(buf),
)
}

View file

@ -29,7 +29,15 @@ use crate::{
PostUpdateForm,
},
traits::{Crud, Likeable, Saveable},
utils::{get_conn, naive_now, DbPool, DELETED_REPLACEMENT_TEXT, FETCH_LIMIT_MAX},
utils::{
get_conn,
naive_now,
DbPool,
DELETED_REPLACEMENT_TEXT,
FETCH_LIMIT_MAX,
SITEMAP_DAYS,
SITEMAP_LIMIT,
},
};
use ::url::Url;
use chrono::{Duration, Utc};
@ -109,8 +117,9 @@ impl Post {
.filter(local.eq(true))
.filter(deleted.eq(false))
.filter(removed.eq(false))
.filter(published.ge(Utc::now().naive_utc() - Duration::days(1)))
.filter(published.ge(Utc::now().naive_utc() - Duration::days(SITEMAP_DAYS)))
.order(published.desc())
.limit(SITEMAP_LIMIT)
.load::<(DbUrl, chrono::DateTime<Utc>)>(conn)
.await
}

View file

@ -49,6 +49,8 @@ use url::Url;
const FETCH_LIMIT_DEFAULT: i64 = 10;
pub const FETCH_LIMIT_MAX: i64 = 50;
pub const SITEMAP_LIMIT: i64 = 50000;
pub const SITEMAP_DAYS: i64 = 31;
const POOL_TIMEOUT: Option<Duration> = Some(Duration::from_secs(5));
pub const RANK_DEFAULT: f64 = 0.0001;