Ruby: working with arrays
well, first of all your first query is extremely ineffective

contender.subscriber.videos.collect { |v| w_hash["comments"] &lt;&lt; v.comments.where("created_at &gt; DATE_SUB( NOW(), INTERVAL 1 DAY)") }


this will query you db for each video you've got

second, you really shouldn't duplicate you SQL queries, i propose that you add scope to your Comment model (you are using Rails 3, right?)

scope :recent, where("created_at &gt; ?", 1.day.ago)


to make your queries more effective you should use .joins method of ActiveRecord

after all this you code would be something like that

comments = Comment.joins(:videos).where(:videos =&gt; { :subscriber =&gt; contender.subscriber }).recent
comments &lt;&lt; contender.profile.comments.recent

w_hash = {}
w_hash["vid_comments"] = comments.collect { |c| !c.media_id.nil? }
w_hash["wall_comments"] = comments.collect { |c| c.parent_id == 0 }