Skip to content

Commit

Permalink
Slightly more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- committed Nov 6, 2019
1 parent d3841a8 commit 40cd2ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/controllers/status_controller.rb
Expand Up @@ -8,7 +8,9 @@ class StatusController < ApplicationController
before_action :verify_admin, only: [:kill]

def index
@statuses = SmokeDetector.includes(:statistics).order(Arel.sql('last_ping DESC')).all
@statuses = SmokeDetector.order(Arel.sql('last_ping DESC')).all
@scans = Statistic.where('created_at >= ?', 24.hours.ago).select(Arel.sql('smoke_detector_id, SUM(posts_scanned) as scans'))
.group(:smoke_detector_id)
end

def status_update
Expand Down
6 changes: 3 additions & 3 deletions app/views/status/index.html.erb
Expand Up @@ -2,11 +2,11 @@

<br />

<table class='table'>
<table class="table">
<tr>
<th>Name</th>
<th>Scans Today</th>
<th style='width:14em;'>Last Ping</th>
<th style="width:14em;">Last Ping</th>
<th colspan="2">
</tr>

Expand All @@ -23,7 +23,7 @@
<% end %>
</td>
<td class="activity-cell">
<%= sd.statistics.where('created_at >= ?', 24.hours.ago).sum(:posts_scanned) %>
<%= @scans.select { |id, scans| id == sd.id }.try(:[], 0) || '(unavailable)' %>
</td>
<td class="status-<%= sd.status_color %> ping-cell" data-livestamp="<%= sd.last_ping.to_i %>" title="<%= sd.last_ping.to_s %>">
<%= time_ago_in_words(sd.last_ping, include_seconds: true)%> ago
Expand Down

0 comments on commit 40cd2ef

Please sign in to comment.