Skip to content

Commit

Permalink
Fix issue ClosureTree#5 by using a deterministic hash function to gen…
Browse files Browse the repository at this point in the history
…erate a lock id for Postgres.
  • Loading branch information
jturkel committed Mar 21, 2013
1 parent 3153a95 commit 94f9d83
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/with_advisory_lock/postgresql.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'zlib'

module WithAdvisoryLock
class PostgreSQL < Base

Expand All @@ -18,7 +20,9 @@ def numeric_lock
if lock_name.is_a? Numeric
lock_name.to_i
else
lock_name.to_s.hash
# Ruby MRI's String#hash is randomly seeded as of Ruby 1.9 so
# make sure we use a deterministic hash.
Zlib.crc32(lock_name.to_s)
end
end
end
Expand Down

1 comment on commit 94f9d83

@mceachen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Merging for v0.0.8

Please sign in to comment.