Open cirosantilli opened 2 years ago
OK, tags now fixed at: 7c37dfbfc7584370deb29bb167f5ac9c35ab746e
Ah, nevermind, reverted that, with that we only get the selected tag when doing the tag search.
Unerlying SQL solution at: https://stackoverflow.com/questions/25734598/get-all-posts-that-have-a-specific-tag-and-keep-all-other-tags-on-results-with-s/70435014#70435014 but needs to be ported to Sequelize. I'm unable to find out how, possible discussion: https://stackoverflow.com/questions/36969162/how-to-include-two-separate-references-of-same-model-using-sequelize-orm
Arghh reverting at def5faaa99de32c983e3933cae02f6dad86ab947 because it breaks count and thus pagination. Gotta add a test for that as well.
Article.toJson
individually gets author. We should get them as a join instead. Same for tags. Otherwise we get 3 queries per row (article author, tag and tag count) / or 5 if logged in (+1 for user likes article, +1 for user follows author), which is insane.Doing http://localhost:3000/api/articles?limit=2&offset=0 while logged off leads to the following reordered/organized list of requests according to
DEBUG='*:sql:*'
:Of those, we could remove all the users and tags queries with joins!
The users JOIN was already in place, we just weren't checking for it properly. Fixed with:
Had tried to fix it previously, but failed because
this.authorPromise === undefined
was always true!The
authorPromise.then(author => author.toProfileJSONFor(user)),
would however make one extra query to see if the current user is following that user or not if were logged in. We would need to also join by following to fix that.