lib/mongoid/locker.rb in mongoid-locker-2.0.1 vs lib/mongoid/locker.rb in mongoid-locker-2.0.2
- old
+ new
@@ -136,12 +136,11 @@
# @return [Mongoid::Criteria]
def locked
where(
'$and': [
{ locking_name_field => { '$exists': true, '$ne': nil } },
- { locked_at_field => { '$exists': true, '$ne': nil } },
- { '$where': "new Date() - this.#{locked_at_field} < #{lock_timeout * 1000}" }
+ { locked_at_field => { '$gte': Time.now.utc - (lock_timeout * 1000) } }
]
)
end
# A scope to retrieve all unlocked documents in the collection.
@@ -166,12 +165,10 @@
'$or': [
{ locking_name_field => { '$eq': nil } },
{ locked_at_field => { '$eq': nil } }
]
},
- {
- '$where': "new Date() - this.#{locked_at_field} >= #{lock_timeout * 1000}"
- }
+ { locked_at_field => { '$lt': Time.now.utc - (lock_timeout * 1000) } }
]
)
end
# Unlock all locked documents in the collection. Sets locking_name_field and locked_at_field fields to nil. Returns number of unlocked documents.