diff --git a/src/main.rs b/src/main.rs index d4808ae..ef888ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -491,7 +491,7 @@ fn all_years<'mw>(req: &mut Request, let groups: Vec = SqlLiteral::new(format!( "select cast(extract(year from date) as int) y, count(*) c \ - from photos{} group by y order by y", + from photos{} group by y order by y desc nulls last", if req.authorized_user().is_none() { " where is_public" } else { @@ -500,7 +500,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 { @@ -508,17 +508,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(); @@ -557,7 +555,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(); @@ -606,7 +604,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(); @@ -657,7 +655,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(); @@ -706,7 +704,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(); diff --git a/src/requestloggermiddleware.rs b/src/requestloggermiddleware.rs index c5e397f..92ba9ae 100644 --- a/src/requestloggermiddleware.rs +++ b/src/requestloggermiddleware.rs @@ -41,10 +41,10 @@ fn fmt_elapsed(t: Duration) -> String { format!("{:.2} s", ms as f32 * 1e-3) } else { let ns = t.num_nanoseconds().unwrap(); - if ns > 1e6 as i64 { - format!("{} ms", ns / 1e6 as i64) - } else if ns > 1000 { - format!("{} us", ns / 1000) + if ns > 10_000_000 { + format!("{} ms", ns / 1000_000) + } else if ns > 10_000 { + format!("{} µs", ns / 1000) } else { format!("{} ns", ns) }