Skip to content

Unscope includes when plucking linkage data#1243

Merged
lgebhardt merged 1 commit intoJSONAPI-Resources:release-0-9from
st0012:fix-1242
Jun 4, 2019
Merged

Unscope includes when plucking linkage data#1243
lgebhardt merged 1 commit intoJSONAPI-Resources:release-0-9from
st0012:fix-1242

Conversation

@st0012
Copy link
Copy Markdown
Contributor

@st0012 st0012 commented Apr 10, 2019

This closes #1242

All Submissions:

  • I've checked to ensure there aren't other open Pull Requests for the same update/change.
  • I've submitted a ticket for my issue if one did not already exist.
  • My submission passes all tests. (Please run the full test suite locally to cut down on noise from travis failures.)
  • I've used Github auto-closing keywords in the commit message or the description.
  • I've added/updated tests for this change.

Bug fixes and Changes to Core Features:

  • I've included an explanation of what the changes do and why I'd like you to include them.
  • I've provided test(s) that fails without the change.

Test Plan:

Reviewer Checklist:

  • Maintains compliance with JSON:API
  • Adequate test coverage exists to prevent regressions

@st0012 st0012 changed the title Unscope includes when plucking linkage data [WIP] Unscope includes when plucking linkage data Apr 10, 2019
It's very common to eager load data in JR. But if we keep includes
values when plucking for linkage data, it can make the query
unnecessarily expensive.

Let's use Post model for example:

If we directly pluck all posts' `created_at` column, the query would be
very simple

```sql
SELECT "posts"."created_at" FROM "posts"
```

But if we keep includes values in the previous relation object, like

```ruby
Post.includes(:author).pluck(:created_at)
```

It generates unnecessarily complicated query

```sql
SELECT "posts"."created_at" FROM "posts" LEFT OUTER JOIN "people" ON
"people"."id" = "posts"."author_id"
```

So we should always unscope includes when we only want to pluck linkage
data.
@st0012 st0012 changed the title [WIP] Unscope includes when plucking linkage data Unscope includes when plucking linkage data Apr 11, 2019
@st0012
Copy link
Copy Markdown
Contributor Author

st0012 commented Apr 11, 2019

@lgebhardt would you mind if I introduce this new gem https://github.com/brigade/db-query-matchers to test the query differnces?

@lgebhardt
Copy link
Copy Markdown
Contributor

@st0012 that seems fine to me

@lgebhardt lgebhardt merged commit 782fc3c into JSONAPI-Resources:release-0-9 Jun 4, 2019
@lgebhardt
Copy link
Copy Markdown
Contributor

@st0012 Thanks!

@st0012
Copy link
Copy Markdown
Contributor Author

st0012 commented Jun 4, 2019

@lgebhardt sorry that I forgot about updating this 😓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants