Skip to content

Commit

Permalink
DEV: Add a default query for Top 50 Largest Uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhnambiar committed Dec 24, 2018
1 parent 2b6357f commit 931bbb6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/queries.rb
Expand Up @@ -46,6 +46,11 @@ def self.default
"id": -8,
"name": "User Participation Statistics",
"description": "Detailed statistics for the most active users"
},
"largest-uploads": {
"id": -9,
"name": "Top 50 Largest Uploads",
"description": "sorted by file size"
}
}.with_indifferent_access

Expand Down Expand Up @@ -287,6 +292,20 @@ def self.default
posts_created DESC
SQL

queries["largest-uploads"]["sql"] = <<~SQL
SELECT posts.id AS post_id,
uploads.original_filename,
ROUND(uploads.filesize / 1000000.0, 2) AS size_in_mb,
uploads.extension,
uploads.created_at,
uploads.url
FROM post_uploads
JOIN uploads ON uploads.id = post_uploads.upload_id
JOIN posts ON posts.id = post_uploads.post_id
ORDER BY uploads.filesize DESC
LIMIT 50
SQL

# convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc.
queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" }
queries
Expand Down

0 comments on commit 931bbb6

Please sign in to comment.