Efficient Active Record on a Search Results Page

Hi everyone!

I’d like to improve the querying done on a search page. The search results are being returned by ElasticSearch in a hash. Now, the tricky part is that each result can display images, and other info pulled from different tables. Right now, there is tons of additional querying in the view which is a no-no. What’s a better way to do handle this?

For example, if I have 40 results per page, and 20 have no images, 10 have to display info from a joined table (“A”), 20 have to display info form a joined table (“B”), etc. My temporary solution is to do some lookups in the view.

If this isn’t clear, please let me know!