sequence_on 0.0.6 → 0.2.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
- SHA1:
3
- metadata.gz: 2650250c9ca169de3a4581fa0e2d07e44e61fe37
4
- data.tar.gz: ff1a627e0a0d887a5dea4f84e46b567c871de144
2
+ SHA256:
3
+ metadata.gz: 88ab0f24b916de10df5233ca70498ba208c16bfc897d5a447c8ba25e139459c7
4
+ data.tar.gz: 5935cd630d7b537a7affc6ac6cccd5249ed4bf5c1b943b51f7c51a1ca899ad1a
5
5
  SHA512:
6
- metadata.gz: 91548be69e31db59c00f2b252276ed13ac2080c747df387ed4bdc1bd32faf73e95c58ca1cde6eb7971a12760c100d9794ec12b4f45416ec4cc27e15027365ed9
7
- data.tar.gz: 07db90399a320135bb17a07a645eca0f1abc2728ef42a593a73218b9ef30943b8b5220cdb6fd5a146e0db4bcff52fb5c3bf4f9f2c79470c5a76cc6c39d348eef
6
+ metadata.gz: 4d4d4912ee560896ec44bc5a22d86ed5ccd8c32653796361a088880961d15379a55a3b8462eea07f5042ce9d0bf5b3cd3d9a0ef89a3ce55209180924723b461b
7
+ data.tar.gz: e2f05f07fc501ad02c7c24b8f82c80e34ccdfbf1a9102a0227094bb7e646a3c0ae6af358fb634be3156eb0af87a1900936901d7c5ddaae82a170148422982f36
@@ -22,20 +22,28 @@ 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?
26
- last_record = if record.persisted?
27
- self.class.class_exec(self, &options[:lmd]).
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?
30
+ last_record = if self.persisted?
31
+ self.class
32
+ .unscoped
33
+ .where(scope).
28
34
  order("#{options[:column]} DESC").
29
35
  where("NOT id = ?", self.id).
30
36
  first
31
37
  else
32
- self.class.class_exec(self, &options[:lmd]).
38
+ self.class
39
+ .unscoped
40
+ .where(scope).
33
41
  order("#{options[:column]} DESC").
34
42
  first
35
43
  end
36
44
 
37
45
  self.sequential_id = if last_record
38
- last_record.send(options[:column]) + 1
46
+ (last_record.send(options[:column]) || 0) + 1
39
47
  else
40
48
  options[:start_at]
41
49
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequence_on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy SEBAN
8
+ - Antonis Tzorvas
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-05-18 00:00:00.000000000 Z
12
+ date: 2021-04-05 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activesupport
@@ -70,7 +71,7 @@ require_paths:
70
71
  - lib
71
72
  required_ruby_version: !ruby/object:Gem::Requirement
72
73
  requirements:
73
- - - "~>"
74
+ - - ">="
74
75
  - !ruby/object:Gem::Version
75
76
  version: '2.3'
76
77
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -79,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []
82
- rubyforge_project:
83
- rubygems_version: 2.4.5
83
+ rubygems_version: 3.0.8
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: Flexible acts_as_sequenced replacement