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

Fix pagination for tags with post_count #5613

Merged
merged 1 commit into from
Aug 10, 2015

Conversation

ErisDS
Copy link
Member

@ErisDS ErisDS commented Jul 29, 2015

closes #5551

  • adds new test fixture generator and tests for tag pagination
  • changes how post_count is added to use a select subquery rather than a join

@ErisDS
Copy link
Member Author

ErisDS commented Jul 29, 2015

Amazing, this is actually failing just on postgres - whoohoo for tests 🎉. Will fix tomorrow.

@ErisDS
Copy link
Member Author

ErisDS commented Jul 30, 2015

Ok, I'm totally baffled by this. Can someone shed some light on the correct way to fix this?

@jaswilli
Copy link
Contributor

The tl;dr is that there are rules about columns appearing in the select list when an aggregate function is involved. Apparently sqlite3 and mysql are just fixing it up for you? I'm not sure. I believe that if you tell bookshelf to add a group by clause with tags.id that postgresql should stop complaining. I think you can get away with leaving the other tags columns out since they're not part of the join result set and aren't causing confusion.

@ErisDS
Copy link
Member Author

ErisDS commented Jul 30, 2015

I've tried adding a groupby but it seems to change the behaviour of the query. I'm not sure if it's complaining about the main query or subquery - I assume subquery because it only errors on those tests, but either way I haven't found a fix that doesn't just cause a different error yet.

@jaswilli
Copy link
Contributor

Sorry, I misjudged what SQL was going to be generated by those bookshelf statements. When I actually ran it through bookshelf the output seems fine to me. Maybe something further down the line from bookshelf (like the pg library or the postgresql optimizer) is making a change? I'm not sure what to do about it--maybe try and rework the query using a different form of the same request.

@jaswilli
Copy link
Contributor

jaswilli commented Aug 1, 2015

I did a little digging and figured out what's going on. Adding the post count subquery makes the SQL generated in the pagination fetchPage method invalid: https://github.com/TryGhost/Ghost/blob/master/core/server/models/base/pagination.js#L147

@ErisDS
Copy link
Member Author

ErisDS commented Aug 2, 2015

Can you explain what about it is invalid? Do you have a link to some docs or something? I'm keen to understand what I did wrong! It seems to work fine even from the pg CLI. I'm very confused!

I figure that the solution is that the post count subquery should be added after the aggregate count, which should be an easy enough change, I'd still like to get a better understanding of what was wrong.

@ErisDS ErisDS force-pushed the issue-5551-tag-pagination branch 2 times, most recently from a0af8a7 to 8d89c3e Compare August 9, 2015 17:59
closes TryGhost#5551

- adds new test fixture generator and tests for tag pagination
- changes how post_count is added to use a select subquery rather than a join
@ErisDS
Copy link
Member Author

ErisDS commented Aug 9, 2015

I have moved the extra count so that it is only added to the collection query, and not the count/aggregate query. This allows all the tests to pass.

This now resolves #5551. There are other issues to do with counts including adding them for other models, and ensuring that they only count public data, but these are tasks listed out in #5615. This at least removes a UI blocker.

sebgie added a commit that referenced this pull request Aug 10, 2015
Fix pagination for tags with post_count
@sebgie sebgie merged commit 5095725 into TryGhost:master Aug 10, 2015
@ErisDS ErisDS deleted the issue-5551-tag-pagination branch August 26, 2015 14:49
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.

Pagination not working on tags endpoint.
3 participants