lib/good_job/lockable.rb in good_job-2.7.1 vs lib/good_job/lockable.rb in good_job-2.7.2
- old
+ new
@@ -213,11 +213,13 @@
<<~SQL.squish
SELECT #{function}(('x'||substr(md5($1::text), 1, 16))::bit(64)::bigint)::text AS locked
SQL
end
- binds = [[nil, key]]
+ binds = [
+ ActiveRecord::Relation::QueryAttribute.new('key', key, ActiveRecord::Type::String.new),
+ ]
self.class.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Advisory Lock', binds).first['locked']
end
# Releases an advisory lock on this record if it is locked by this database
# session. Note that advisory locks stack, so you must call
@@ -227,11 +229,13 @@
# @return [Boolean] whether the lock was released.
def advisory_unlock(key: lockable_key, function: self.class.advisory_unlockable_function(advisory_lockable_function))
query = <<~SQL.squish
SELECT #{function}(('x'||substr(md5($1::text), 1, 16))::bit(64)::bigint) AS unlocked
SQL
- binds = [[nil, key]]
+ binds = [
+ ActiveRecord::Relation::QueryAttribute.new('key', key, ActiveRecord::Type::String.new),
+ ]
self.class.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Advisory Unlock', binds).first['unlocked']
end
# Acquires an advisory lock on this record or raises
# {RecordAlreadyAdvisoryLockedError} if it is already locked by another
@@ -277,11 +281,14 @@
WHERE pg_locks.locktype = 'advisory'
AND pg_locks.objsubid = 1
AND pg_locks.classid = ('x' || substr(md5($1::text), 1, 16))::bit(32)::int
AND pg_locks.objid = (('x' || substr(md5($2::text), 1, 16))::bit(64) << 32)::bit(32)::int
SQL
- binds = [[nil, key], [nil, key]]
+ binds = [
+ ActiveRecord::Relation::QueryAttribute.new('key', key, ActiveRecord::Type::String.new),
+ ActiveRecord::Relation::QueryAttribute.new('key', key, ActiveRecord::Type::String.new),
+ ]
self.class.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Advisory Locked?', binds).any?
end
# Tests whether this record does not have an advisory lock on it.
# @param key [String, Symbol] Key to test lock against
@@ -301,10 +308,13 @@
AND pg_locks.objsubid = 1
AND pg_locks.classid = ('x' || substr(md5($1::text), 1, 16))::bit(32)::int
AND pg_locks.objid = (('x' || substr(md5($2::text), 1, 16))::bit(64) << 32)::bit(32)::int
AND pg_locks.pid = pg_backend_pid()
SQL
- binds = [[nil, key], [nil, key]]
+ binds = [
+ ActiveRecord::Relation::QueryAttribute.new('key', key, ActiveRecord::Type::String.new),
+ ActiveRecord::Relation::QueryAttribute.new('key', key, ActiveRecord::Type::String.new),
+ ]
self.class.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Owns Advisory Lock?', binds).any?
end
# Releases all advisory locks on the record that are held by the current
# database session.