[Stats] Fix an issue caused by division by zero (#874)

Fixes #865
This commit is contained in:
Cinder 2025-02-03 08:29:24 -08:00 committed by GitHub
parent c3e0dd6588
commit 654023250f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -61,7 +61,8 @@ class StatsUpdater
stats[:total_forum_threads] = ForumTopic.count
stats[:total_forum_posts] = ForumPost.maximum("id") || 0
stats[:average_posts_per_thread] = (stats[:total_forum_posts] / stats[:total_forum_threads]).round
stats[:average_posts_per_thread] = 0
stats[:average_posts_per_thread] = (stats[:total_forum_posts] / stats[:total_forum_threads]).round if stats[:total_forum_threads] > 0
stats[:average_forum_posts_per_day] = daily_average.call(stats[:total_forum_posts])
### Blips ###

View File

@ -12,7 +12,13 @@
<td><%= data_title %></td>
<td><%= del(@stats[data_or_stats_key]) || data_or_stats_key %></td>
<% if data_total_key %>
<td class="stats-pct"><%= (@stats[data_or_stats_key].to_f / @stats[data_total_key] * 100).round %>%</td>
<td class="stats-pct">
<% if @stats[data_total_key] > 0 %>
<%= (@stats[data_or_stats_key].to_f / @stats[data_total_key] * 100).round %>%
<% else %>
0%
<% end %>
</td>
<% else %>
<td></td>
<% end %>