culturecode_stagehand 0.12.7 → 0.12.8

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
  SHA1:
3
- metadata.gz: ef4f7ed707fdd603dee78f606e921ad59fbdf1ae
4
- data.tar.gz: bb179ffa8b7e83eebc77f8588b3391b7da3f9de9
3
+ metadata.gz: 157594f1ea15ea034a9c883c00835b44bc6d6bef
4
+ data.tar.gz: f42ed40749d2ac477e5d3c064bc9bb306331a4e2
5
5
  SHA512:
6
- metadata.gz: 34f3b335af3dd3012fd2e5d4d25c4e92a2c050de854a2dbd2f8ef120280912816f622baed085e1d20f97ea9aea68c08f59700169f1fc9b6b404dc4ec3b5889e5
7
- data.tar.gz: 2ef4879e631f9fc512eab292206ada48631707c3bec2a374611ca0c50927dfbe444fcdce42b578e6ccbc70e8fed429ca0bbeeee3fda72b7d1ce69ed83bebfd8b
6
+ metadata.gz: b6bfe97dcb0695d74e415dbaa74ab0d3e425027833fe4afb660ceb7f354db7a2c93ca3d2d1da58ae6fd95e66ceef86fc6891b41c1b675b3496692ff0618c2021
7
+ data.tar.gz: 2240f17970315f0fb0d7fd64f999bef1a6374903f190cbb01cefa0561edbcd18f87da879b8dedc012137045e02bf198e1f97fbcfb64a3eeea223f511c43ae688
@@ -29,7 +29,8 @@ module Stagehand
29
29
  ON active_starts.session = #{table_name}.session AND active_starts.start_id <= #{table_name}.id")
30
30
  .where("active_starts.start_id IS NULL") }
31
31
  scope :with_uncontained_keys, lambda {
32
- joins("LEFT OUTER JOIN (#{ unscoped.contained.select('record_id, table_name').distinct.to_sql}) AS contained
32
+ uncontained
33
+ .joins("LEFT OUTER JOIN (#{ unscoped.contained.select('record_id, table_name').distinct.to_sql}) AS contained
33
34
  ON contained.record_id = #{table_name}.record_id AND contained.table_name = #{table_name}.table_name")
34
35
  .where("contained.record_id IS NULL")
35
36
  }
@@ -83,14 +83,12 @@ module Stagehand
83
83
  # Lazily iterate through millions of commit entries
84
84
  # Returns commit entries in ID descending order
85
85
  def iterate_autosyncable_entries(&block)
86
- max = CommitEntry.maximum(:id)
87
- min = CommitEntry.minimum(:id)
86
+ max = CommitEntry.maximum(:id).to_i
87
+ min = CommitEntry.minimum(:id).to_i
88
88
 
89
89
  max.step(min, -BATCH_SIZE).each do |current|
90
90
  range = [current - BATCH_SIZE, min].max..current
91
- autosyncable_entries(:id => range).uniq(&:id).each do |entry|
92
- with_confirmed_autosyncability(entry, &block)
93
- end
91
+ with_confirmed_autosyncability(autosyncable_entries(:id => range).order(:id => :desc), &block)
94
92
  end
95
93
  end
96
94
 
@@ -98,15 +96,25 @@ module Stagehand
98
96
  # This confirmation is used to guard against writes to the record that occur after loading an initial list of
99
97
  # entries that are autosyncable, but before the record is actually synced. To prevent this, a lock on the record
100
98
  # is acquired and then the record's autosync eligibility is rechecked before calling the block.
101
- def with_confirmed_autosyncability(entry, &block)
99
+ def with_confirmed_autosyncability(entries, &block)
100
+ entries = Array.wrap(entries)
101
+ return unless entries.present?
102
+
102
103
  Database.transaction do
103
- CommitEntry.connection.execute("SELECT 1 FROM #{entry.table_name} WHERE id = #{entry.record_id}")
104
- block.call(entry) if autosyncable_entries(:record_id => entry.record_id, :table_name => entry.table_name).exists?
104
+ # Lock the records so nothing can update them
105
+ CommitEntry.connection.execute(CommitEntry.where(:id => entries).lock.to_sql)
106
+
107
+ # Execute the block for each entry we've confirm autosyncability
108
+ confirmed_ids = Set.new(autosyncable_entries.where(:id => entries).pluck(:id))
109
+
110
+ entries.each do |entry|
111
+ block.call(entry) if confirmed_ids.include?(entry.id)
112
+ end
105
113
  end
106
114
  end
107
115
 
108
116
  def autosyncable_entries(scope = nil)
109
- entries = CommitEntry.content_operations.not_in_progress.where(scope).order(:id => :desc)
117
+ entries = CommitEntry.content_operations.not_in_progress.where(scope)
110
118
  entries = entries.with_uncontained_keys unless Configuration.ghost_mode?
111
119
  return entries
112
120
  end
@@ -1,3 +1,3 @@
1
1
  module Stagehand
2
- VERSION = "0.12.7"
2
+ VERSION = "0.12.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: culturecode_stagehand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.7
4
+ version: 0.12.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Jakobsen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-01 00:00:00.000000000 Z
12
+ date: 2017-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails