I made what I think is a small change yet the change in my app was
disastrous - cpu spun, memory went out of control, and mongrel crashed
I have a controller which takes a param for submission_id . Submissions
have 1 or more reviews, and reviews each have one image. There may be
than one image per submission.
The view (and partial) code does some very intense things, like @
submission.reviews.each | review |
, etc. No doubt causes huge joins and queries down the stack.
I built a query for a subset of the reviews belonging to @submission:
@current_reviews = Review.find(:all, :conditions => cond)
The query takes 20 milliseconds. [cond is along the lines of finding
max(id) where [email protected] group by image_id ]
Then when I try to loop thru these in view, replacing @
submission.reviews.each with @current_reviews.each , it leaks like
Same code works just fine w/ @submission.reviews.each…
The partial that it’s rendering in that loop is huge - 150 lines of
with all kinds of join-inducing references. Why would this behavior be
different for a SUBSET ?
Thanks in advance for any insights, things to try, places to look, etc.