synced 1.5.1 → 1.5.2

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: 45ac855b6dcbc774f96b065d7cca0db58e354724
4
- data.tar.gz: e324632b4c8c3dc4bdcf5d9be705a9dc7a639256
3
+ metadata.gz: 3b57fd9809319aece800d98be7cb7d595af42183
4
+ data.tar.gz: ceb98bf9015b4877d597f4d89a73c63627ad8353
5
5
  SHA512:
6
- metadata.gz: bd8f4a9991f7bde53aac5af37f7c1d5c5a41cff58482e6b8729eacfc8de51e9781a25cb3da023d2dd3a06f3cc60f1dfab23a840067db1d5524c35b091690d6b4
7
- data.tar.gz: d23988c8e74e182a8612b3845440f27f8c99de4442a2ad77b8d27e6dc6327dce00d62878b4a36827259173b7a39bddb0b7c7b70f3a1b5ccfb7e69dd325921b10
6
+ metadata.gz: 498ac45444e90dac7dba56d8c79bb644c61a89fd5da85c1225612a86dc0d5fae59cb6570d744d2c5c7b4d3176dd0936c36d304f7aadfa97d672bd4b2a4b38125
7
+ data.tar.gz: 43493baddef335a7c0602949071ba5602cc0e9519e746fc7f737f86a9fc327a8c6d5dda260bc2ec68249d060e3293dc67a5aac0100cde3527dd4300b49fd0988
@@ -25,11 +25,16 @@ module Synced
25
25
  end
26
26
 
27
27
  def remote_objects_tester
28
- lambda do |remote_objects|
29
- @remote_objects_ids.concat(remote_objects.map(&:id))
28
+ lambda do |remote_objects_batch|
29
+ remote_objects_batch_ids = remote_objects_batch.map(&:id)
30
+ local_objects = relation_scope.where(@id_key => remote_objects_batch_ids)
31
+ local_objects_hash = local_objects.each_with_object({}) do |local_object, hash|
32
+ hash[local_object.public_send(@id_key)] = local_object
33
+ end
34
+ @remote_objects_ids.concat(remote_objects_batch_ids)
30
35
 
31
- remote_objects.map do |remote|
32
- if local_object = local_object_by_remote_id(remote.id)
36
+ remote_objects_batch.map do |remote|
37
+ if local_object = local_objects_hash[remote.id]
33
38
  remote.extend(@mapper) if @mapper
34
39
  local_object.attributes = default_attributes_mapping(remote)
35
40
  local_object.attributes = local_attributes_mapping(remote)
@@ -89,14 +89,19 @@ module Synced
89
89
  private
90
90
 
91
91
  def remote_objects_persistor
92
- lambda do |remote_objects|
92
+ lambda do |remote_objects_batch|
93
93
  additional_errors_check
94
- @remote_objects_ids.concat(remote_objects.map(&:id))
94
+ remote_objects_batch_ids = remote_objects_batch.map(&:id)
95
+ local_objects = relation_scope.where(@id_key => remote_objects_batch_ids)
96
+ local_objects_hash = local_objects.each_with_object({}) do |local_object, hash|
97
+ hash[local_object.public_send(@id_key)] = local_object
98
+ end
99
+ @remote_objects_ids.concat(remote_objects_batch_ids)
95
100
 
96
101
  processed_objects =
97
- remote_objects.map do |remote|
102
+ remote_objects_batch.map do |remote|
98
103
  remote.extend(@mapper) if @mapper
99
- local_object = local_object_by_remote_id(remote.id) || relation_scope.new
104
+ local_object = local_objects_hash[remote.id] || relation_scope.new
100
105
  local_object.attributes = default_attributes_mapping(remote)
101
106
  local_object.attributes = local_attributes_mapping(remote)
102
107
  if @globalized_attributes.present?
@@ -172,14 +177,6 @@ module Synced
172
177
  @api ||= closest.try(:api) || raise(MissingAPIClient.new(@scope, @model_class))
173
178
  end
174
179
 
175
- def local_object_by_remote_id(remote_id)
176
- local_objects.find { |l| l.public_send(@id_key) == remote_id }
177
- end
178
-
179
- def local_objects
180
- relation_scope.where(@id_key => remote_objects_ids).to_a
181
- end
182
-
183
180
  def remote_objects_ids
184
181
  @remote_objects_ids
185
182
  end
@@ -1,3 +1,3 @@
1
1
  module Synced
2
- VERSION = "1.5.1"
2
+ VERSION = "1.5.2"
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.5.1
4
+ version: 1.5.2
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: 2017-02-27 00:00:00.000000000 Z
12
+ date: 2017-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails