aboutsummaryrefslogtreecommitdiff
path: root/src/db/mod.rs
diff options
context:
space:
mode:
authorNathan Perry <avaglir@gmail.com>2019-04-09 02:05:07 -0400
committerNathan Perry <avaglir@gmail.com>2019-04-09 02:05:07 -0400
commit74bd3dfdd7c57beb2bc84b6abaabd514558cba5d (patch)
tree071bd0d4d59f9095d1565c32ad6f222121f2585a /src/db/mod.rs
parent0a1ce5c5bb1bd6174e12bba971ebd8b3bc451b41 (diff)
report most popular random meme in stats
Diffstat (limited to 'src/db/mod.rs')
-rw-r--r--src/db/mod.rs20
1 files changed, 20 insertions, 0 deletions
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,
}
@@ -407,6 +410,20 @@ pub fn stats(conn: &PgConnection) -> Result<Stats> {
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
GROUP BY memes.title
ORDER BY COUNT(*) DESC
LIMIT 1;
@@ -439,6 +456,9 @@ pub fn stats(conn: &PgConnection) -> Result<Stats> {
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,
})