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 +4 -4
- data/lib/sequence_on/sequenced_on.rb +7 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb00257dc44535b3ce99fccbd174c4eb74f3a48a000fe209fb11ccbf2b40009c
|
4
|
+
data.tar.gz: c1411b03daa76183c24e6f3ca42ffd861ed3e5815f1a7b37fe2264e757073ee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
.
|
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
|
-
.
|
40
|
+
.where(scope).
|
37
41
|
order("#{options[:column]} DESC").
|
38
42
|
first
|
39
43
|
end
|