From 616dd60b31358ab7bee95ba4896faab6d274d862 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 22 Mar 2010 12:09:24 -0400 Subject: [PATCH] When reports are kept in the database and not deleted/purged the Host.reports.last query starts slowing down and the hosts index page can take minutes to load depending on the number of hosts. By changing Host.reports.last to Host.find(host.id).reports.maximum('id') we make a more efficient query to the database cutting the lookup time. --- app/controllers/hosts_controller.rb | 2 +- app/helpers/hosts_helper.rb | 2 +- vendor/plugins/active_scaffold | 1 - vendor/plugins/active_scaffold_list_filter | 1 - vendor/plugins/acts_as_audited | 1 - vendor/plugins/ruby-net-ldap | 1 - vendor/plugins/will_paginate | 1 - vendor/rails | 1 - 8 files changed, 2 insertions(+), 8 deletions(-) delete mode 160000 vendor/plugins/active_scaffold delete mode 160000 vendor/plugins/active_scaffold_list_filter delete mode 160000 vendor/plugins/acts_as_audited delete mode 160000 vendor/plugins/ruby-net-ldap delete mode 160000 vendor/plugins/will_paginate delete mode 160000 vendor/rails diff --git a/app/controllers/hosts_controller.rb b/app/controllers/hosts_controller.rb index a5d3d5f..8a238a0 100644 --- a/app/controllers/hosts_controller.rb +++ b/app/controllers/hosts_controller.rb @@ -111,7 +111,7 @@ class HostsController < ApplicationController # shows the last report for a host def report # is it safe to assume that the biggest ID is the last report? - redirect_to :controller => "reports", :action => "show", :id => Host.find(params[:id]).reports.last + redirect_to :controller => "reports", :action => "show", :id => Report.find(Host.find(params[:id]).reports.maximum('id')) end # shows all reports for a certian host diff --git a/app/helpers/hosts_helper.rb b/app/helpers/hosts_helper.rb index 91caebb..891adfa 100644 --- a/app/helpers/hosts_helper.rb +++ b/app/helpers/hosts_helper.rb @@ -3,7 +3,7 @@ module HostsHelper return nil if record.last_report.nil? time = time_ago_in_words(record.last_report.getlocal) image_tag("#{not (record.error_count > 0 or record.no_report)}.png", :size => "18x18") + - link_to_if(record.reports.last, time, report_host_path(record)) + link_to_if(Report.find(Host.find(record.id).reports.maximum('id')), time, report_host_path(record)) end def root_pass_form_column(record, field_name) diff --git a/vendor/plugins/active_scaffold b/vendor/plugins/active_scaffold deleted file mode 160000 index 7c5a3e9..0000000 --- a/vendor/plugins/active_scaffold +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7c5a3e9ec9ae8432a2190cd2ef741cb78d605f35 diff --git a/vendor/plugins/active_scaffold_list_filter b/vendor/plugins/active_scaffold_list_filter deleted file mode 160000 index 4356ed5..0000000 --- a/vendor/plugins/active_scaffold_list_filter +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4356ed54ca78ba1c68a1e626ea4e8bd73b515fa4 diff --git a/vendor/plugins/acts_as_audited b/vendor/plugins/acts_as_audited deleted file mode 160000 index a150a7d..0000000 --- a/vendor/plugins/acts_as_audited +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a150a7d1502e16de878c60bbac4c821d7960b8e8 diff --git a/vendor/plugins/ruby-net-ldap b/vendor/plugins/ruby-net-ldap deleted file mode 160000 index ba08042..0000000 --- a/vendor/plugins/ruby-net-ldap +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ba08042d75ae930578a96846ae7180e8bf450846 diff --git a/vendor/plugins/will_paginate b/vendor/plugins/will_paginate deleted file mode 160000 index 3d531e1..0000000 --- a/vendor/plugins/will_paginate +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3d531e169db92a16a9a8974f0ae6edf52e52659e diff --git a/vendor/rails b/vendor/rails deleted file mode 160000 index bfe0328..0000000 --- a/vendor/rails +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bfe032858077bb2946abe25e95e485ba6da86bd5 -- 1.5.5.6