DEV: Add a default query for Top 50 Largest Uploads

This commit is contained in:
Rishabh 2018-12-24 14:03:57 +05:30
parent 2b6357f8b4
commit 931bbb67a0
1 changed files with 19 additions and 0 deletions

View File

@ -46,6 +46,11 @@ class Queries
"id": -8, "id": -8,
"name": "User Participation Statistics", "name": "User Participation Statistics",
"description": "Detailed statistics for the most active users" "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 }.with_indifferent_access
@ -287,6 +292,20 @@ class Queries
posts_created DESC posts_created DESC
SQL 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. # convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc.
queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" } queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" }
queries queries