From 5b57b7de88517d86ae970f522d5174b87c8050d9 Mon Sep 17 00:00:00 2001 From: Rasmus Kaj Date: Fri, 11 Nov 2016 21:49:58 +0100 Subject: [PATCH] Put nulls last in some orderings. --- src/main.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index a633577..867338b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -456,7 +456,7 @@ fn all_years<'mw>(req: &mut Request, .load::<(Option, i64)>(c).unwrap() .iter().map(|&(year, count)| { let q = Photo::query(req.authorized_user().is_some()) - .order((grade.desc(), date.asc())) + .order((grade.desc().nulls_last(), date.asc())) .limit(1); let photo = if let Some(year) = year { @@ -464,17 +464,15 @@ fn all_years<'mw>(req: &mut Request, .and_hms(0, 0, 0))) .filter(date.lt(NaiveDate::from_ymd(year + 1, 1, 1) .and_hms(0, 0, 0))) - .first::(c).unwrap() } else { q.filter(date.is_null()) - .first::(c).unwrap() }; Group { title: year.map(|y|format!("{}", y)) .unwrap_or("-".to_string()), url: format!("/{}/", year.unwrap_or(0)), count: count, - photo: photo + photo: photo.first::(c).unwrap() } }).collect(); @@ -513,7 +511,7 @@ fn months_in_year<'mw>(req: &mut Request, let photo = Photo::query(req.authorized_user().is_some()) .filter(date.ge(fromdate)) .filter(date.lt(todate)) - .order((grade.desc(), date.asc())) + .order((grade.desc().nulls_last(), date.asc())) .limit(1) .first::(c).unwrap(); @@ -562,7 +560,7 @@ fn days_in_month<'mw>(req: &mut Request, let photo = Photo::query(req.authorized_user().is_some()) .filter(date.ge(fromdate)) .filter(date.lt(fromdate + ChDuration::days(1))) - .order((grade.desc(), date.asc())) + .order((grade.desc().nulls_last(), date.asc())) .limit(1) .first::(c).unwrap(); @@ -613,7 +611,7 @@ fn all_for_day<'mw>(req: &mut Request, let photos: Vec = Photo::query(req.authorized_user().is_some()) .filter(date.ge(thedate)) .filter(date.lt(thedate + ChDuration::days(1))) - .order((grade.desc(), date.asc())) + .order((grade.desc().nulls_last(), date.asc())) .limit(500) .load(c).unwrap(); @@ -662,7 +660,7 @@ fn on_this_day<'mw>(req: &mut Request, let photo = Photo::query(req.authorized_user().is_some()) .filter(date.ge(fromdate)) .filter(date.lt(fromdate + ChDuration::days(1))) - .order((grade.desc(), date.asc())) + .order((grade.desc().nulls_last(), date.asc())) .limit(1) .first::(c).unwrap();