On 2012-07-02, at 17:40 , aram harrow wrote:
> A sidebar displaying recent comments is now up.
> Let me know if this broke anything.
While nothing seems broken, I would implement things differently in two ways.
I don't think it's a good idea to call Paper.find and User.find from the view. If we need to do that, we should probably be doing it in the controller. In this case there's no need, since given a comment c, c.user and c.paper return the relevant user or paper. I'd prefer in general if we did very little in views other than handle formatting and displaying information, as they're not easy to read with all the ruby embedded into the HTML.
This doesn't solve my other problem: when we start from a list of comments and then find the user and paper associated with each comment individually, it requires 2n database queries to find the information we want. This is pretty much the classic 'n+1' problem and is usually solvable by telling active record what information to fetch with the first query.
I've made changes that make me happier and committed them -- hopefully you don't mind if I edit your code.
There are also a bunch of test cases now failing (at least on my machine) relating to displaying papers. Nothing appears broken, so it may just be that the test cases can't handle the recent formatting changes, but I'll try to have a look and figure things out. I'll also plan to add test cases to cover recent comments, author links, etc.
Bill