Browse Source

serve: limit events to 2 weeks

master
Astro 12 months ago
parent
commit
26e14b1d90
  1. 5
      ticker-serve/src/index.rs

5
ticker-serve/src/index.rs

@ -9,7 +9,7 @@ use mime::TEXT_HTML;
use typed_html::{html, text, dom::DOMTree, types::{Class, SpacedSet}};
use diesel::prelude::*;
use chrono::{offset::Local, Datelike, NaiveDate};
use chrono::{offset::Local, Datelike, Duration, NaiveDate};
use libticker::{
schema::{self, events::dsl::events},
@ -56,8 +56,11 @@ fn group_by_day(es: &[Event]) -> Vec<DayEvents> {
fn render_index(app_state: &AppState) -> String {
let db = app_state.db.lock().unwrap();
let today = Local::today().naive_local().and_hms(0, 0, 0);
let limit = Local::today().naive_local().and_hms(0, 0, 0) +
Duration::weeks(2);
let es = events
.filter(schema::events::dtstart.ge(&today))
.filter(schema::events::dtstart.lt(&limit))
.order_by(schema::events::dtstart.asc())
.then_order_by(schema::events::dtend.desc())
.load::<Event>(&*db)

Loading…
Cancel
Save