synced 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3293144a530b0b41b214912ec147152b207e4b2
4
- data.tar.gz: a016b6c1cb3628884c5c465a2c84e9f167c83a36
3
+ metadata.gz: 4e12f68714c45cb3257ac0116c7412e34879bff8
4
+ data.tar.gz: 07828256826de59fcb3e8e0c8da913270bab003d
5
5
  SHA512:
6
- metadata.gz: 9b42ca3a24e7d58cfd666a01de3c8c22e28bd67db53f74649a77c678e6212b5e689977d3158a96d202bc3167e0dd41d180ea858e01c9ea29639fd5e95ef2e9e4
7
- data.tar.gz: e9da5291a6c4fbbb7a2e52078b6a4817e6b6cd631eb6acbaeefa519ace7db4ebc295af66235065561ac48c0766c8d5cb8a10b6144a1b81c565196b89d0338eba
6
+ metadata.gz: aad5845c643c3a8485db188837bf7f43307513c8cbf3092b0e190a4759ffb00dd879ba74cfa0f77798128c0b81ab7710db268eec8e14fed782d51d4389b53195
7
+ data.tar.gz: f000eb92f1ccb6d09b10a10995571240f8619612206129305faa8a7283809169ed02a656cf9a50e775fecb93e847a8c35e4cfd2f64ca98992b1f94c8942f716a
data/README.md CHANGED
@@ -226,8 +226,29 @@ By default `Synced::Strategies::SyncedAllAtTimestampStrategy` strategy is used,
226
226
  overhead on updating the timestamps on all the records.
227
227
 
228
228
  There is also a `Synced::Strategies::SyncedPerScopeTimestampStrategy`, that uses another model,
229
- `Synced::Timestamp`, to store the synchronization timestamps. Migration can be copied from the synced dummy app
230
- `spec/dummy/db/migrate/20160126082137_create_synced_timestamps.rb`.
229
+ `Synced::Timestamp`, to store the synchronization timestamps. You can generate the migration the following way:
230
+
231
+ ```
232
+ rails generate migration create_synced_timestamps
233
+ ```
234
+
235
+ and copy the body from here:
236
+
237
+ ```
238
+ class CreateSyncedTimestamps < ActiveRecord::Migration
239
+ def change
240
+ create_table :synced_timestamps do |t|
241
+ t.belongs_to :parent_scope, polymorphic: true
242
+ t.string :model_class, null: false
243
+ t.datetime :synced_at, null: false
244
+ end
245
+
246
+ add_index :synced_timestamps, [:parent_scope_id, :parent_scope_type, :synced_at], name: 'synced_timestamps_max_index', order: { synced_at: 'DESC' }
247
+ end
248
+ end
249
+ ```
250
+
251
+
231
252
  This strategy is added to fix the problems with massive updates on `synced_all_at`. Proper cleanup of timestamp records
232
253
  is needed once in a while with `Synced::Timestamp.cleanup` (cleans records older than 1 week).
233
254
 
@@ -5,21 +5,36 @@ module Synced
5
5
  # This is a strategy for UpdatedSince defining how to store and update synced timestamps.
6
6
  # It uses a separate timestamps table to track when different models were synced in specific scopes.
7
7
  class SyncedPerScopeTimestampStrategy
8
- def initialize(scope:, model_class:, **_options)
8
+ attr_reader :scope, :model_class
9
+ private :scope, :model_class
10
+
11
+ def initialize(scope: nil, model_class:, **_options)
9
12
  @scope = scope
10
13
  @model_class = model_class
11
14
  end
12
15
 
13
16
  def last_synced_at
14
- Synced::Timestamp.with_scope_and_model(@scope, @model_class).last_synced_at
17
+ timestamp_repository.last_synced_at
15
18
  end
16
19
 
17
20
  def update(timestamp)
18
- Synced::Timestamp.with_scope_and_model(@scope, @model_class).create!(synced_at: timestamp)
21
+ timestamp_repository.create!(synced_at: timestamp)
19
22
  end
20
23
 
21
24
  def reset
22
- Synced::Timestamp.with_scope_and_model(@scope, @model_class).delete_all
25
+ timestamp_repository.delete_all
26
+ end
27
+
28
+ private
29
+
30
+ def timestamp_repository
31
+ @timestamp_repository ||= begin
32
+ if scope
33
+ Synced::Timestamp.with_scope_and_model(scope, model_class)
34
+ else
35
+ Synced::Timestamp.with_model(model_class)
36
+ end
37
+ end
23
38
  end
24
39
  end
25
40
  end
@@ -1,9 +1,15 @@
1
1
  class Synced::Timestamp < ActiveRecord::Base
2
- self.table_name = 'synced_timestamps'
2
+ self.table_name = "synced_timestamps"
3
+
3
4
  belongs_to :parent_scope, polymorphic: true
4
- scope :with_scope_and_model, ->(parent_scope, model_class) { where(parent_scope: parent_scope, model_class: model_class.to_s) }
5
- validates :parent_scope, :model_class, :synced_at, presence: true
6
- scope :old, -> { where('synced_at < ?', 1.week.ago) }
5
+
6
+ validates :model_class, :synced_at, presence: true
7
+
8
+ scope :with_scope_and_model, -> (parent_scope, model_class) {
9
+ where(parent_scope: parent_scope, model_class: model_class.to_s)
10
+ }
11
+ scope :with_model, -> model_class { where(model_class: model_class.to_s) }
12
+ scope :old, -> { where("synced_at < ?", 1.week.ago) }
7
13
 
8
14
  def model_class=(value)
9
15
  write_attribute(:model_class, value.to_s)
@@ -1,3 +1,3 @@
1
1
  module Synced
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synced
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastien Grosjean
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-01 00:00:00.000000000 Z
12
+ date: 2016-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  version: '0'
211
211
  requirements: []
212
212
  rubyforge_project:
213
- rubygems_version: 2.4.3
213
+ rubygems_version: 2.4.8
214
214
  signing_key:
215
215
  specification_version: 4
216
216
  summary: Keep your BookingSync Application synced with BookingSync.