Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify cache key to prevent errors and incorrect data returned. Fixes #1344 #1346

Closed
wants to merge 24 commits into from

Conversation

kevintyll
Copy link
Contributor

When caching, return the object's cache_key up front if it's defined. This will prevent objects PORO objects that don't have updated_at defined, from throwing an error. Not as big a deal now that PORO objects can inherit ActiveModelSerializers::Model, but still necessary if it's not inherited for whatever reason.

Add the Adapter type to the cache key. This prevents incorrect results when the same object is serialized with different adapters.

fixes #1344

… This will prevent objects PORO objects that don't have updated_at defined, from throwing an error. Not as big a deal now that PORO objects can inherit ActiveModelSerializers::Model, but still necessary if it's not inherited for whatever reason.

Add the Adapter type to the cache key.  This prevents incorrect results when the same object is serialized with different adapters.
@kevintyll kevintyll changed the title Modify cache key to prevent errors and incorrect data returned. Modify cache key to prevent errors and incorrect data returned. Fixes #1344 Nov 25, 2015
@@ -55,7 +55,7 @@ def self.digest_caller_file(caller_line)

serializer.class_attribute :_cache # @api private : the cache object
serializer.class_attribute :_fragmented # @api private : @see ::fragmented
serializer.class_attribute :_cache_key # @api private : when present, is first item in cache_key
serializer.class_attribute :_cache_key # @api private : when present, is first item in cache_key. Ignored if the serialized object defines #cache_key.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/serialized/serializable ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know what you're asking here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the diff, to change Ignored if the serialized object defines #cache_key. to Ignored if the serializable object defines #cache_key.

@bf4
Copy link
Member

bf4 commented Dec 23, 2015

@kevintyll hi :)

@kevintyll
Copy link
Contributor Author

Hi, sorry I haven't responded. I haven't had a chance to work on your suggestions yet. I'm hoping to be able to get to them after the first of the year.

bf4 added 5 commits December 23, 2015 09:45
For discussion:

Consider evaluating association in serializer context

That way, associations are really just anything that
can be conditionally included.  They no longer
have to actually be methods on the object or serializer.

e.g.

```diff
has_many :comments do
- last(1)
+ Comment.active.for_serialization(object).last(1)
end
```
@bf4
Copy link
Member

bf4 commented Dec 30, 2015

soon... :)

@bf4
Copy link
Member

bf4 commented Jan 5, 2016

🌅

@kevintyll
Copy link
Contributor Author

Hoping to get to it Wednesday.

parts = []
parts << object_cache_key
parts << adapter_instance.class.to_s.demodulize.underscore
parts << @klass._cache_digest unless @klass._cache_options && @klass._cache_options[:skip_digest]
parts.join('/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • TODO: urgh, we need to document this option (note to self)

…ister to change it's signature. Not sure if that is okay or not.
@kevintyll
Copy link
Contributor Author

Let me know about the change I made to the register method with the adapter#name. I'll continue tomorrow.

@bf4
Copy link
Member

bf4 commented Jan 6, 2016

The inclusion of adapter type is a good idea but the impl change is too big for this pr, needs to be discussed elsewhere... I'm ok surfacing the adapter name as a class method, but interface of registering shouldn't change here (reviewing on phone, pardon if I missed something.)

@bf4
Copy link
Member

bf4 commented Jan 6, 2016

I think serializer#cache_key is the more fundamental change #1346 (comment)

… This will prevent objects PORO objects that don't have updated_at defined, from throwing an error. Not as big a deal now that PORO objects can inherit ActiveModelSerializers::Model, but still necessary if it's not inherited for whatever reason.

Add the Adapter type to the cache key.  This prevents incorrect results when the same object is serialized with different adapters.
…ister to change it's signature. Not sure if that is okay or not.
… on adapter, though that leaves a disconnect with the naming in the register method.
Conflicts:
	lib/active_model/serializer.rb
	lib/active_model/serializer/adapter/base.rb
	lib/active_model/serializer/adapter/cached_serializer.rb
	test/fixtures/poro.rb
	test/serializers/cache_test.rb
@kevintyll
Copy link
Contributor Author

Okay, I think I got it all. Not sure what happened to the diff. Looks like it's picking things up from the merge of master into my fork.

@bf4
Copy link
Member

bf4 commented Jan 6, 2016

Probably rebase and force push helps

B mobile phone

On Jan 6, 2016, at 1:32 PM, Kevin Tyll notifications@github.com wrote:

Okay, I think I got it all. Not sure what happened to the diff. Looks like it's picking things up from the merge of master into my fork.


Reply to this email directly or view it on GitHub.

@kevintyll
Copy link
Contributor Author

Rebasing didn't do anything. Had some issues merging upstream into my fork. I probably screwed up the commit history. I confident the code is correctly merged though.

@bf4
Copy link
Member

bf4 commented Mar 31, 2016

Continued in #1642

@bf4 bf4 closed this Mar 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues with #object_cache_key method
3 participants