JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Add a hook for retrieving ActiveRecord fragments for included relationships
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Description
For example, if you have a resource UserResource with a method like this
def friends
@model.friends.size
end
It will load user.friends separately for each model in the list. So you can optimise the query like this:
class self.records
_model_class.all.includes(:friends)
end
Then when requesting GET /users/ it now works well. However, say if you request something like GET /groups/?include=users, the records method on UserResource is never called, so there is no query optimisation.
Instead of overriding self.apply_includes(records, options = {}) on each resource that has a relationship to UserResource, it would be nice to have a way to do this only once per resource.
@lgebhardt as discussed on Gitter
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how GET /groups/?include=users reaches UserResource, and compare the records and apply_includes paths described in the issue. The work is done when one resource-level hook can optimize included relationships without overriding apply_includes on every related resource, while avoiding separate queries for each model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- api, backend, database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100