mirror of
https://github.com/neocities/neocities.git
synced 2025-08-26 19:03:26 +02:00
fix for bandwidth display on dashboard
This commit is contained in:
parent
28b85c9f08
commit
df1339e1d0
2 changed files with 16 additions and 4 deletions
|
@ -1932,9 +1932,21 @@ class Site < Sequel::Model
|
|||
end
|
||||
|
||||
def monthly_bandwidth_used
|
||||
stat = stats_dataset.order(:created_at.desc).select(:bandwidth).first
|
||||
return 0 if stat.nil?
|
||||
stat[:bandwidth]
|
||||
current_month_start = Date.new(Date.today.year, Date.today.month, 1)
|
||||
next_month_start = current_month_start.next_month
|
||||
|
||||
result = stats_dataset
|
||||
.where(created_at: current_month_start...next_month_start)
|
||||
.sum(:bandwidth)
|
||||
|
||||
return result || 0
|
||||
end
|
||||
|
||||
def bandwidth_percentage_used
|
||||
used = monthly_bandwidth_used
|
||||
max = maximum_monthly_bandwidth
|
||||
return 0 if max == 0 || used == 0
|
||||
((used.to_f / max) * 100).round(1)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<li>Using <strong><%= current_site.space_percentage_used %>% (<%= current_site.total_space_used.to_space_pretty %>)</strong> of your <strong><%= current_site.maximum_space.to_space_pretty %></strong> storage.
|
||||
<br>
|
||||
<li>
|
||||
Used <strong><%= current_site.monthly_bandwidth_used.to_bytes_pretty %></strong> of bandwidth this month.
|
||||
Used <strong><%= current_site.bandwidth_percentage_used %>% (<%= current_site.monthly_bandwidth_used.to_bytes_pretty %>)</strong> of your <strong><%= current_site.maximum_monthly_bandwidth.to_bytes_pretty %></strong> bandwidth this month.
|
||||
<br>
|
||||
<% unless current_site.is_education || current_site.supporter? %>Need more space? <a href="/supporter">Become a Supporter!</a><% end %>
|
||||
</li>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue