Skip to content
Permalink
Browse files

DEV: Add a default query for Top 50 Largest Uploads

  • Loading branch information...
rishabhnambiar committed Dec 24, 2018
1 parent 2b6357f commit 931bbb67a07a57965c3da8ca471ee2283eeb1f27
Showing with 19 additions and 0 deletions.
  1. +19 −0 lib/queries.rb
@@ -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

@@ -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

0 comments on commit 931bbb6

Please sign in to comment.
You can’t perform that action at this time.