sequence_on 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3aa62bb7a536c393c87c1e1b301c66a843aece721e9654de0c47595d09809632
4
- data.tar.gz: df56836b57565a113e844aed981a5555406a1407d7cf12b0e00b109bd3b17231
3
+ metadata.gz: eb00257dc44535b3ce99fccbd174c4eb74f3a48a000fe209fb11ccbf2b40009c
4
+ data.tar.gz: c1411b03daa76183c24e6f3ca42ffd861ed3e5815f1a7b37fe2264e757073ee4
5
5
  SHA512:
6
- metadata.gz: 17e45f0e1848dae93156d7aafcda729536a83e97247a042dc47659934b01cdc59afd231f6431f5970a5d41da15f3784e0c423471d0f849289d85fc3e10acec46
7
- data.tar.gz: 5595fcc9f1fa08ebd6ef05116d88b9eb1d6059b69184c055d769f0bc33d10fe5d8b52d9a6fbc0011e0a88e91303237e1692b65af6b27643e0865c09604c6cbef
6
+ metadata.gz: 877a2cd9e3c7be2d13c3c1938809b045b2bb2209a65f6ca2ae6471f8c6a453b543570ff925e3ce08350ddda603faa72c87e122300383baafac7c0e6857bb7439
7
+ data.tar.gz: 4d9d3f2be589eb9a968a45e10af7710fc8e192d77de8748a184354c8535a381e564fdec679df80dc1f2c027a712127d21e78c3f87cdd872c380ff15c32d11a1d
@@ -22,18 +22,22 @@ module SequenceOn
22
22
  def generate_sequence_id
23
23
  return if self.sequential_id
24
24
  options = self.class.sequence_options
25
- self.class.connection.execute("LOCK TABLE #{self.class.table_name} IN EXCLUSIVE MODE") if postgresql?
25
+ scope = self.class.class_exec(self, &options[:lmd])
26
+ lock_candidates = scope.values
27
+ lock_key = Digest::MD5.hexdigest(lock_candidates.join).unpack('L').join
28
+
29
+ self.class.connection.execute("SELECT pg_advisory_xact_lock('#{self.class.table_name}'::regclass::integer, #{lock_key})", "sequence_on") if postgresql?
26
30
  last_record = if self.persisted?
27
31
  self.class
28
32
  .unscoped
29
- .class_exec(self, &options[:lmd]).
33
+ .where(scope).
30
34
  order("#{options[:column]} DESC").
31
35
  where("NOT id = ?", self.id).
32
36
  first
33
37
  else
34
38
  self.class
35
39
  .unscoped
36
- .class_exec(self, &options[:lmd]).
40
+ .where(scope).
37
41
  order("#{options[:column]} DESC").
38
42
  first
39
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequence_on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy SEBAN