Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F1090711
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Oct 15, 10:53 AM
Size
3 KB
Mime Type
text/x-diff
Expires
Fri, Oct 17, 10:53 AM (1 d, 15 h)
Engine
blob
Format
Raw Data
Handle
280599
Attached To
rARCHIVING archiving
View Options
diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb
index b958e7b..b23777c 100644
--- a/app/controllers/clients_controller.rb
+++ b/app/controllers/clients_controller.rb
@@ -1,31 +1,35 @@
class ClientsController < ApplicationController
before_action :set_client, only: :show
before_action :fetch_logs
# GET /clients
def index
@client_ids = Client.for_user(current_user.id).pluck(:ClientId)
@clients = Client.where(ClientId: @client_ids).includes(:jobs)
- @active_jobs = Job.running.where(ClientId: @client_ids).group(:ClientId).count
@hosts = current_user.hosts.not_baculized
+ fetch_jobs_info
get_charts
end
# GET /clients/1
def show
@client_ids = [@client.id]
get_charts
end
private
def set_client
@client = Client.for_user(current_user.id).find(params[:id])
end
+ def fetch_jobs_info
+ @stats = JobStats.new(@client_ids)
+ end
+
def get_charts
days_ago = params.fetch(:days_back, 7).to_i rescue 7
@job_status = ChartGenerator.job_statuses(@client_ids, days_ago)
@job_stats = ChartGenerator.job_stats(@client_ids, days_ago - 1)
end
end
diff --git a/app/views/clients/_client.html.erb b/app/views/clients/_client.html.erb
index 3e5337b..012e4b3 100644
--- a/app/views/clients/_client.html.erb
+++ b/app/views/clients/_client.html.erb
@@ -1,11 +1,11 @@
<tr>
<td><%= link_to client.name, client %></td>
<td><%= client.uname %></td>
- <td><%= @active_jobs[client.id] || 0 %></td>
- <td><%= client.last_job_date_formatted %></td>
+ <td><%= @stats.active_jobs[client.id] || 0 %></td>
+ <td><%= @stats.last_jobs[client.id] %></td>
<td><%= client.file_retention_days %></td>
<td><%= client.job_retention_days %></td>
- <td><%= number_to_human_size(client.backup_jobs_size) %></td>
- <td><%= number_by_magnitude(client.files_count) %></td>
+ <td><%= number_to_human_size(@stats.jobs_sizes[client.id]) %></td>
+ <td><%= number_by_magnitude(@stats.jobs_files[client.id]) %></td>
<td><%= client.auto_prune_human %></td>
</tr>
diff --git a/lib/job_stats.rb b/lib/job_stats.rb
new file mode 100644
index 0000000..0ea608c
--- /dev/null
+++ b/lib/job_stats.rb
@@ -0,0 +1,36 @@
+# Helper class that fetches job stats for the desired clients
+class JobStats
+ attr_reader :client_ids, :active_jobs, :last_jobs, :jobs_sizes, :jobs_files
+
+ # Initializes the object.
+ def initialize(client_ids=nil)
+ @client_ids = client_ids
+ fetch_stats
+ end
+
+ private
+
+ # Assigns values to:
+ #
+ # * active_jobs
+ # * last_jobs
+ # * jobs_sizes
+ # * jobs_files
+ def fetch_stats
+ @active_jobs = Job.running
+ @active_jobs = @active_jobs.where(ClientId: client_ids) if client_ids
+ @active_jobs = @active_jobs.group(:ClientId).count
+
+ @last_jobs = {}
+ @jobs_sizes = Hash.new { |h,k| h[k] = 0 }
+ @jobs_files = Hash.new { |h,k| h[k] = 0 }
+
+ jobs = Job.backup_type.order(EndTime: :asc)
+ jobs = jobs.where(ClientId: client_ids) if client_ids
+ jobs.each do |job|
+ @last_jobs[job.client_id] = I18n.l(job.end_time, format: :long) if job.end_time
+ @jobs_sizes[job.client_id] += job.job_bytes
+ @jobs_files[job.client_id] += job.job_files
+ end
+ end
+end
Event Timeline
Log In to Comment