mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FEATURE: Improve backup stats on admin dashboard
* Dashboard doesn't timeout anymore when Amazon S3 is used for backups * Storage stats are now a proper report with the same caching rules * Changing the backup_location, s3_backup_bucket or creating and deleting backups removes the report from the cache * It shows the number of backups and the backup location * It shows the used space for the correct backup location instead of always showing used space on local storage * It shows the date of the last backup as relative date
This commit is contained in:
@ -18,7 +18,7 @@ module BackupRestore
|
||||
|
||||
# @return [Array<BackupFile>]
|
||||
def files
|
||||
unsorted_files.sort_by { |file| -file.last_modified.to_i }
|
||||
@files ||= unsorted_files.sort_by { |file| -file.last_modified.to_i }
|
||||
end
|
||||
|
||||
# @return [BackupFile]
|
||||
@ -26,6 +26,11 @@ module BackupRestore
|
||||
files.first
|
||||
end
|
||||
|
||||
def reset_cache
|
||||
@files = nil
|
||||
Report.clear_cache(:storage_stats)
|
||||
end
|
||||
|
||||
def delete_old
|
||||
return unless cleanup_allowed?
|
||||
return if (backup_files = files).size <= SiteSetting.maximum_backups
|
||||
@ -33,6 +38,8 @@ module BackupRestore
|
||||
backup_files[SiteSetting.maximum_backups..-1].each do |file|
|
||||
delete_file(file.filename)
|
||||
end
|
||||
|
||||
reset_cache
|
||||
end
|
||||
|
||||
def remote?
|
||||
@ -60,6 +67,15 @@ module BackupRestore
|
||||
fail NotImplementedError
|
||||
end
|
||||
|
||||
def stats
|
||||
{
|
||||
used_bytes: used_bytes,
|
||||
free_bytes: free_bytes,
|
||||
count: files.size,
|
||||
last_backup_taken_at: latest_file&.last_modified
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# @return [Array<BackupFile>]
|
||||
@ -70,5 +86,13 @@ module BackupRestore
|
||||
def cleanup_allowed?
|
||||
true
|
||||
end
|
||||
|
||||
def used_bytes
|
||||
files.sum { |file| file.size }
|
||||
end
|
||||
|
||||
def free_bytes
|
||||
fail NotImplementedError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user