-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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
Conversation
Amazing, this is actually failing just on postgres - whoohoo for tests 🎉. Will fix tomorrow. |
Ok, I'm totally baffled by this. Can someone shed some light on the correct way to fix this? |
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 |
I've tried adding a |
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. |
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 |
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. |
a0af8a7
to
8d89c3e
Compare
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
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. |
Fix pagination for tags with post_count
closes #5551