Put nulls last in some orderings.

This commit is contained in:
Rasmus Kaj 2016-11-11 21:49:58 +01:00
parent 4b6b927640
commit 5b57b7de88

View File

@ -456,7 +456,7 @@ fn all_years<'mw>(req: &mut Request,
.load::<(Option<i32>, 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::<Photo>(c).unwrap()
} else {
q.filter(date.is_null())
.first::<Photo>(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::<Photo>(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::<Photo>(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::<Photo>(c).unwrap();
@ -613,7 +611,7 @@ fn all_for_day<'mw>(req: &mut Request,
let photos: Vec<Photo> = 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::<Photo>(c).unwrap();