synced 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -2
- data/lib/synced/strategies/synced_per_scope_timestamp_strategy.rb +19 -4
- data/lib/synced/timestamp.rb +10 -4
- data/lib/synced/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e12f68714c45cb3257ac0116c7412e34879bff8
|
4
|
+
data.tar.gz: 07828256826de59fcb3e8e0c8da913270bab003d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
230
|
-
|
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
|
-
|
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
|
-
|
17
|
+
timestamp_repository.last_synced_at
|
15
18
|
end
|
16
19
|
|
17
20
|
def update(timestamp)
|
18
|
-
|
21
|
+
timestamp_repository.create!(synced_at: timestamp)
|
19
22
|
end
|
20
23
|
|
21
24
|
def reset
|
22
|
-
|
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
|
data/lib/synced/timestamp.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
class Synced::Timestamp < ActiveRecord::Base
|
2
|
-
self.table_name =
|
2
|
+
self.table_name = "synced_timestamps"
|
3
|
+
|
3
4
|
belongs_to :parent_scope, polymorphic: true
|
4
|
-
|
5
|
-
validates :
|
6
|
-
|
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)
|
data/lib/synced/version.rb
CHANGED
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.
|
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-
|
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.
|
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.
|