mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-29 21:01:03 +00:00
Sitemap - use UTC time (#3914)
* change local filter to use `eq` function * use Utc time for sitemap
This commit is contained in:
parent
514f2222e0
commit
26d125cc63
2 changed files with 13 additions and 13 deletions
|
@ -3,22 +3,20 @@ use actix_web::{
|
|||
web::Data,
|
||||
HttpResponse,
|
||||
};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use lemmy_api_common::context::LemmyContext;
|
||||
use lemmy_db_schema::{newtypes::DbUrl, source::post::Post};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
use sitemap_rs::{url::Url, url_set::UrlSet};
|
||||
use tracing::info;
|
||||
|
||||
async fn generate_urlset(posts: Vec<(DbUrl, chrono::NaiveDateTime)>) -> LemmyResult<UrlSet> {
|
||||
async fn generate_urlset(
|
||||
posts: Vec<(DbUrl, chrono::DateTime<chrono::Utc>)>,
|
||||
) -> LemmyResult<UrlSet> {
|
||||
let urls = posts
|
||||
.into_iter()
|
||||
.map_while(|post| {
|
||||
Url::builder(post.0.to_string())
|
||||
.last_modified(DateTime::from_utc(
|
||||
post.1,
|
||||
FixedOffset::east_opt(0).expect("Error setting timezone offset"), // TODO what is the proper timezone offset here?
|
||||
))
|
||||
.last_modified(post.1.into())
|
||||
.build()
|
||||
.ok()
|
||||
})
|
||||
|
@ -48,27 +46,29 @@ pub(crate) mod tests {
|
|||
#![allow(clippy::unwrap_used)]
|
||||
|
||||
use crate::sitemap::generate_urlset;
|
||||
use chrono::{NaiveDate, NaiveDateTime};
|
||||
use chrono::{DateTime, NaiveDate, Utc};
|
||||
use elementtree::Element;
|
||||
use lemmy_db_schema::newtypes::DbUrl;
|
||||
use url::Url;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_generate_urlset() {
|
||||
let posts: Vec<(DbUrl, NaiveDateTime)> = vec![
|
||||
let posts: Vec<(DbUrl, DateTime<Utc>)> = vec![
|
||||
(
|
||||
Url::parse("https://example.com").unwrap().into(),
|
||||
NaiveDate::from_ymd_opt(2022, 12, 1)
|
||||
.unwrap()
|
||||
.and_hms_opt(9, 10, 11)
|
||||
.unwrap(),
|
||||
.unwrap()
|
||||
.and_utc(),
|
||||
),
|
||||
(
|
||||
Url::parse("https://lemmy.ml").unwrap().into(),
|
||||
NaiveDate::from_ymd_opt(2023, 1, 1)
|
||||
.unwrap()
|
||||
.and_hms_opt(1, 2, 3)
|
||||
.unwrap(),
|
||||
.unwrap()
|
||||
.and_utc(),
|
||||
),
|
||||
];
|
||||
|
||||
|
|
|
@ -101,16 +101,16 @@ impl Post {
|
|||
|
||||
pub async fn list_for_sitemap(
|
||||
pool: &mut DbPool<'_>,
|
||||
) -> Result<Vec<(DbUrl, chrono::NaiveDateTime)>, Error> {
|
||||
) -> Result<Vec<(DbUrl, chrono::DateTime<Utc>)>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
post
|
||||
.select((ap_id, coalesce(updated, published)))
|
||||
.filter(local)
|
||||
.filter(local.eq(true))
|
||||
.filter(deleted.eq(false))
|
||||
.filter(removed.eq(false))
|
||||
.filter(published.ge(Utc::now().naive_utc() - Duration::days(1)))
|
||||
.order(published.desc())
|
||||
.load::<(DbUrl, chrono::NaiveDateTime)>(conn)
|
||||
.load::<(DbUrl, chrono::DateTime<Utc>)>(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue