From 4b1fbec6f449f8273f9be268935c654b109ca4ff Mon Sep 17 00:00:00 2001 From: Roman Shterenzon Date: Mon, 8 Apr 2013 11:55:43 +0300 Subject: [PATCH] Instead of performing a redundant query, just wrap the result --- lib/delayed/backend/mongoid.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/delayed/backend/mongoid.rb b/lib/delayed/backend/mongoid.rb index 11da91b..e778dcb 100644 --- a/lib/delayed/backend/mongoid.rb +++ b/lib/delayed/backend/mongoid.rb @@ -67,8 +67,10 @@ def self.reserve(worker, max_run_time = Worker.max_run_time) ) # Return result as a Mongoid document. - # When Mongoid starts supporting findAndModify, this extra step should no longer be necessary. - self.find(:first, :conditions => {:_id => result["_id"]}) unless result.nil? + new.tap do |job| + job.new_record = false + job.assign_attributes(result) + end unless result.nil? rescue Mongo::OperationFailure nil # no jobs available end