mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Add Top Uploads report (#6825)
Co-Authored-By: I am very Pro-Grammer. <khalilovcmded@users.noreply.github.com>
This commit is contained in:
@@ -1433,6 +1433,72 @@ class Report
|
||||
}
|
||||
end
|
||||
|
||||
def self.report_top_uploads(report)
|
||||
report.modes = [:table]
|
||||
|
||||
report.labels = [
|
||||
{
|
||||
type: :link,
|
||||
properties: [
|
||||
:file_url,
|
||||
:file_name,
|
||||
],
|
||||
title: I18n.t("reports.top_uploads.labels.filename")
|
||||
},
|
||||
{
|
||||
type: :user,
|
||||
properties: {
|
||||
username: :author_username,
|
||||
id: :author_id,
|
||||
avatar: :author_avatar_template,
|
||||
},
|
||||
title: I18n.t("reports.top_uploads.labels.author")
|
||||
},
|
||||
{
|
||||
type: :text,
|
||||
property: :extension,
|
||||
title: I18n.t("reports.top_uploads.labels.extension")
|
||||
},
|
||||
{
|
||||
type: :bytes,
|
||||
property: :filesize,
|
||||
title: I18n.t("reports.top_uploads.labels.filesize")
|
||||
},
|
||||
]
|
||||
|
||||
report.data = []
|
||||
|
||||
sql = <<~SQL
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
u.username,
|
||||
u.uploaded_avatar_id,
|
||||
up.filesize,
|
||||
up.original_filename,
|
||||
up.extension,
|
||||
up.url
|
||||
FROM uploads up
|
||||
JOIN users u
|
||||
ON u.id = up.user_id
|
||||
WHERE up.created_at >= '#{report.start_date}' AND up.created_at <= '#{report.end_date}'
|
||||
ORDER BY up.filesize DESC
|
||||
LIMIT #{report.limit || 250}
|
||||
SQL
|
||||
|
||||
DB.query(sql).each do |row|
|
||||
data = {}
|
||||
data[:author_id] = row.user_id
|
||||
data[:author_username] = row.username
|
||||
data[:author_avatar_template] = User.avatar_template(row.username, row.uploaded_avatar_id)
|
||||
data[:filesize] = row.filesize
|
||||
data[:extension] = row.extension
|
||||
data[:file_url] = Discourse.store.cdn_url(row.url)
|
||||
data[:file_name] = row.original_filename.truncate(25)
|
||||
|
||||
report.data << data
|
||||
end
|
||||
end
|
||||
|
||||
DiscourseEvent.on(:site_setting_saved) do |site_setting|
|
||||
if ["backup_location", "s3_backup_bucket"].include?(site_setting.name.to_s)
|
||||
clear_cache(:storage_stats)
|
||||
|
||||
Reference in New Issue
Block a user