-
Notifications
You must be signed in to change notification settings - Fork 12
Inconsistence between CachedResourcesProcessor#process_resources vs SimpleResourcesProcessor#process_resources #31
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
Comments
After I investigate the issue, it seems
What we expect the return value should be I am on Rails 5.1.4. |
Hi @samnang – you are right. There is a fix for Rails 5 in jsonapi-rb/jsonapi-rails#70, and I'll try to cut new releases of all gems next week. gem 'jsonapi-renderer', github: 'jsonapi-rb/jsonapi-renderer'
gem 'jsonapi-rails', github: 'jsonapi-rb/jsonapi-rails', branch: 'json-caching' |
Thank @beauby, you saved my day. I have been tried different options to get it to work, but none of them are good. |
@beauby I have few questions that try to understand how the caching work here:
|
Hi @samnang
Not sure I understand, but what is cached is a fragment of JSON representing a resource (along with its relationships' linkage data).
Each resource will be fetched (though using
It caches individual resources. |
When I start implementing caching in my app, I noticed CachedResourcesProcessor#process_resources returns an array of strings, but SimpleResourcesProcessor#process_resources returns an array of hashes.
I assume the api should expect to return an array of hashes, so that when Rails' controllers calls
render
in jsonapi-rails, it converts that data hash into json correctly, but if it's a string, it willto_json
again on string which I don't think we want that behaviour.Option 1
Change
CachedResourcesProcessor#process_resources
to return array of hash:Pros: Consistency API.
Cons: It's a bit slow if we do with big data because it has to convert json data back and forth.
Option 2
Change
jsonapi-rails
to not callingto_json
again if it's already in string.Pros: It's fast because we don't need to do double works on converting json data.
Cons: Inconsistency API between
CachedResourcesProcessor#process_resources
vsSimpleResourcesProcessor#process_resources
.Edit: Option 2 is not working because
renderer.render(resources, options, self)
return jsonapi respone data hash not justdata
attribute.The text was updated successfully, but these errors were encountered: