c42/survey-web — pull request #21 by timothyandrew (2013-03-24 18:32:21+00:00)
Title: Performance Fix for the Reports Page

The current reports page gets a list of valid questions using `Survey#questions_for_reports` and then iterates over these questions and calls the `report_data` method on each one.

The problem is, the `questions_for_reports` method is incorrect. For a survey with 38 questions, it returns ~ 2k items.

![](http://f.cl.ly/items/260N0Y1a190S3O272O2j/abc.png)

The easier solution (IMO) is to iterate through *all* the questions of the survey, call `report_data` on each one, and don't render anything if `report_data` returns an empty array.

This pull request does exactly that. With this patch, the reports page for the Type 4 Survey with Production Data (about 160 responses) loads in under 10 seconds.

-----

It's possible I'm missing some edge case that necessitated pre-calculating the questions required. In that case, the `questions_for_reports` method needs to be fixed.

If not, I don't see any other problem with this approach.

Please comment with your thoughts.