From 631e76324b431a4b840273c79abde48e34a3cc9e Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Wed, 20 Sep 2017 23:40:07 +0200 Subject: [PATCH] Cleanup. Make use of .first() and .optional() from Diesel --- src/state.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/state.rs b/src/state.rs index 8eece77..61494eb 100644 --- a/src/state.rs +++ b/src/state.rs @@ -75,9 +75,8 @@ impl State { Ok(article_revisions::table .filter(article_revisions::article_id.eq(article_id)) .filter(article_revisions::revision.eq(revision)) - .limit(1) - .load::(&*connection_pool.get()?)? - .pop()) + .first::(&*connection_pool.get()?) + .optional()?) }) } @@ -100,14 +99,13 @@ impl State { Ok(match article_revisions::table .filter(article_revisions::slug.eq(slug)) .order(article_revisions::sequence_number.desc()) - .limit(1) .select(( article_revisions::article_id, article_revisions::revision, article_revisions::latest, )) - .load::(&*conn)? - .pop() + .first::(&*conn) + .optional()? { None => SlugLookup::Miss, Some(ref stub) if stub.latest => SlugLookup::Hit { @@ -118,11 +116,8 @@ impl State { article_revisions::table .filter(article_revisions::latest.eq(true)) .filter(article_revisions::article_id.eq(stub.article_id)) - .limit(1) .select(article_revisions::slug) - .load::(&*conn)? - .pop() - .expect("Data model requires this to exist") + .first::(&*conn)? ) }) }) @@ -141,15 +136,12 @@ impl State { let (latest_revision, prev_title, prev_slug) = article_revisions::table .filter(article_revisions::article_id.eq(article_id)) .order(article_revisions::revision.desc()) - .limit(1) .select(( article_revisions::revision, article_revisions::title, article_revisions::slug, )) - .load::<(i32, String, String)>(&*conn)? - .pop() - .unwrap_or_else(|| unimplemented!("TODO Missing an error type")); + .first::<(i32, String, String)>(&*conn)?; if latest_revision != base_revision { // TODO: If it is the same edit repeated, just respond OK