-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Sync To User performance (batch 3) (#1898)
- Loading branch information
1 parent
d78d0ca
commit 8ff7ba1
Showing
7 changed files
with
30 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -606,6 +606,7 @@ DEPENDENCIES | |
memery | ||
memory_profiler | ||
mock_redis | ||
oj | ||
ougai | ||
parallel | ||
parallel_tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
class Api::V3::Transformer | ||
class << self | ||
def from_request(attributes_of_payload) | ||
rename_attributes(attributes_of_payload, key_mapping) | ||
def from_request(payload_attributes) | ||
rename_attributes(payload_attributes, from_request_key_mapping) | ||
end | ||
|
||
def to_response(model) | ||
rename_attributes(model.attributes, inverted_key_mapping).as_json | ||
rename_attributes(model.attributes, to_response_key_mapping).as_json | ||
end | ||
|
||
def rename_attributes(attributes, mapping) | ||
mapping = mapping.with_indifferent_access | ||
attributes | ||
.to_hash | ||
.except(*mapping.values) | ||
.transform_keys! { |key| mapping[key] || key } | ||
.with_indifferent_access | ||
replace_keys(attributes.to_hash, mapping).with_indifferent_access | ||
end | ||
|
||
def key_mapping | ||
def replace_keys(hsh, mapping) | ||
mapping.each do |k, v| | ||
hsh[v] = hsh.delete(k) | ||
end | ||
hsh | ||
end | ||
|
||
def from_request_key_mapping | ||
{ | ||
"created_at" => "device_created_at", | ||
"updated_at" => "device_updated_at" | ||
} | ||
end | ||
|
||
def inverted_key_mapping | ||
key_mapping.invert | ||
def to_response_key_mapping | ||
from_request_key_mapping.invert | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters