From 74bd3dfdd7c57beb2bc84b6abaabd514558cba5d Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Tue, 9 Apr 2019 02:05:07 -0400 Subject: report most popular random meme in stats --- src/db/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/db') diff --git a/src/db/mod.rs b/src/db/mod.rs index a331ead..6cc09b4 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -272,6 +272,9 @@ pub struct Stats { pub most_popular_named_meme: String, pub most_popular_named_meme_count: usize, + pub most_popular_random_meme: String, + pub most_popular_random_meme_count: usize, + pub most_popular_meme_overall: String, pub most_popular_meme_overall_count: usize, } @@ -404,6 +407,20 @@ pub fn stats(conn: &PgConnection) -> Result { let most_requested_meme = row.get(0); let most_requested_meme_count: i64 = row.get(1); + let rows = raw_conn.query(r#" + SELECT memes.title, COUNT(*) FROM invocation_records + INNER JOIN memes ON meme_id = memes.id + WHERE random IS TRUE + GROUP BY memes.title + ORDER BY COUNT(*) DESC + LIMIT 1; + "#, &[])?; + + let row = rows.get(0); + + let most_random_meme = row.get(0); + let most_random_meme_count: i64 = row.get(1); + let rows = raw_conn.query(r#" SELECT memes.title, COUNT(*) FROM invocation_records INNER JOIN memes ON meme_id = memes.id @@ -439,6 +456,9 @@ pub fn stats(conn: &PgConnection) -> Result { most_popular_named_meme: most_requested_meme, most_popular_named_meme_count: most_requested_meme_count as usize, + most_popular_random_meme: most_random_meme, + most_popular_random_meme_count: most_random_meme_count as usize, + most_popular_meme_overall: most_invoked_meme, most_popular_meme_overall_count: most_invoked_meme_count as usize, }) -- cgit v1.3.1