-
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.
Revert "Improve Sync To User performance (batch 3) (#1898)"
This reverts commit 8ff7ba1.
- Loading branch information
Showing
7 changed files
with
22 additions
and
30 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 |
---|---|---|
|
@@ -608,7 +608,6 @@ 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,33 +1,31 @@ | ||
class Api::V3::Transformer | ||
class << self | ||
def from_request(payload_attributes) | ||
rename_attributes(payload_attributes, from_request_key_mapping) | ||
def from_request(attributes_of_payload) | ||
rename_attributes(attributes_of_payload, key_mapping) | ||
end | ||
|
||
def to_response(model) | ||
rename_attributes(model.attributes, to_response_key_mapping).as_json | ||
rename_attributes(model.attributes, inverted_key_mapping).as_json | ||
end | ||
|
||
def rename_attributes(attributes, mapping) | ||
replace_keys(attributes.to_hash, mapping).with_indifferent_access | ||
mapping = mapping.with_indifferent_access | ||
attributes | ||
.to_hash | ||
.except(*mapping.values) | ||
.transform_keys! { |key| mapping[key] || key } | ||
.with_indifferent_access | ||
end | ||
|
||
def replace_keys(hsh, mapping) | ||
mapping.each do |k, v| | ||
hsh[v] = hsh.delete(k) | ||
end | ||
hsh | ||
end | ||
|
||
def from_request_key_mapping | ||
def key_mapping | ||
{ | ||
"created_at" => "device_created_at", | ||
"updated_at" => "device_updated_at" | ||
} | ||
end | ||
|
||
def to_response_key_mapping | ||
from_request_key_mapping.invert | ||
def inverted_key_mapping | ||
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