From 024e00ba535cda71a7e10641ee24a90b6c9bcbad Mon Sep 17 00:00:00 2001 From: Soren Christensen Date: Thu, 4 Apr 2013 12:56:38 -0700 Subject: [PATCH] Replaced Ruby count with SQL count - significantly faster and far less memory consumed. --- lib/hirefireapp/middleware.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hirefireapp/middleware.rb b/lib/hirefireapp/middleware.rb index c58302c..9540360 100644 --- a/lib/hirefireapp/middleware.rb +++ b/lib/hirefireapp/middleware.rb @@ -91,11 +91,11 @@ def count_delayed_job where(:failed_at => nil). where('run_at <= ?', Time.now).count else - Delayed::Job.all( + Delayed::Job.count(:id, :conditions => [ 'failed_at IS NULL and run_at <= ?', Time.now.utc ] - ).count + ) end elsif defined?(Mongoid) and backend?(/Mongoid/) Delayed::Job.where(