Skip to content

Commit

Permalink
Fix caching 2 (#19)
Browse files Browse the repository at this point in the history
* Fix caching issue for SF ORM object

* Fix caching issue

* Update comment
  • Loading branch information
vishalvijay committed Dec 26, 2017
1 parent 60e0a30 commit 550fb87
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
salesforce-orm (1.2.4)
salesforce-orm (1.2.5)
activerecord (~> 3)
activerecord-nulldb-adapter (~> 0)
restforce (~> 2.5)
Expand Down
41 changes: 31 additions & 10 deletions lib/salesforce-orm/object_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,37 @@ def to_hash
def inspect
to_h
end
end

# Fix for unable to cache object of this class.
# This is a temporary solution. Once Restforce::Mash fix this issue, we'll revert this change
# WARNING: As of now, you can't do any restforce operation on the object of this class which is fetched from cache
def marshal_dump
h = to_h
h[:attributes] = Restforce::Mash.new(attributes.to_h) if attributes
h[:original_object] = Restforce::SObject.new(original_object.to_h) if original_object
h[:original_object][:attributes] = Restforce::Mash.new(original_object.attributes.to_h) if original_object && original_object.attributes
h
# marshal_dump and marshal_load is a fix for unable to cache object of this class.
# This is a temporary solution. Once Restforce::Mash fix this issue, we'll revert this change

def marshal_dump
h = to_h
if h[:attributes]
h[:attributes] = h[:attributes].clone
h[:attributes].instance_variable_set(:@client, nil)
end

if h[:original_object]
h[:original_object] = h[:original_object].clone
h[:original_object].instance_variable_set(:@client, nil)

if h[:original_object]['attributes']
h[:original_object]['attributes'] = h[:original_object]['attributes'].clone
h[:original_object]['attributes'].instance_variable_set(:@client, nil)
end
end
h
end

def marshal_load(data)
result = super(data)

attributes.instance_variable_set(:@client, RestforceClient.instance) if attributes
original_object.instance_variable_set(:@client, RestforceClient.instance) if original_object
original_object.attributes.instance_variable_set(:@client, RestforceClient.instance) if original_object && original_object.attributes

result
end
end
end
2 changes: 1 addition & 1 deletion lib/salesforce-orm/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SalesforceOrm
VERSION = '1.2.4'.freeze
VERSION = '1.2.5'.freeze
end

0 comments on commit 550fb87

Please sign in to comment.