Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial crack at correct .includes on home page queries

  • Loading branch information...
commit bff5fcc39108535fed748384d7ff63663b137a0c 1 parent cc77f83
@sudara authored
View
10 app/controllers/assets_controller.rb
@@ -82,15 +82,15 @@ def latest
wants.html do
@limit = (params[:latest] && params[:latest].to_i < 50) ? params[:latest] : 5
@page_title = @description = "Latest #{@limit} uploaded mp3s" if params[:latest]
- @assets = Asset.latest(@limit)
+ @assets = Asset.latest(@limit).includes(:user => :pic)
@favorites = Track.favorites.limit(5)
- @popular = Asset.limit(@limit).order('hotness DESC')
+ @popular = Asset.limit(@limit).order('hotness DESC').includes(:user => :pic)
@comments = if admin?
- Comment.include_private.limit(5)
+ Comment.on_track.include_private.limit(5).includes(:commentable => :user)
else
- Comment.public.by_member.limit(5)
+ Comment.on_track.public.by_member.limit(5).includes(:commentable => :user)
end
- @playlists = Playlist.public.latest(12)
+ @playlists = Playlist.public.latest(12).includes(:pic)
@tab = 'home'
@welcome = true unless logged_in?
@feature = Feature.published.first
View
1  app/models/comment.rb
@@ -5,6 +5,7 @@ class Comment < ActiveRecord::Base
scope :public, recent.where(:spam => false).where(:private => false)
scope :by_member, recent.where('commenter_id IS NOT NULL')
scope :include_private, recent.where(:spam => false)
+ scope :on_track, where(:commentable_type => 'Asset')
belongs_to :commentable, :polymorphic => true, :touch => true
View
4 app/views/assets/_asset_tabs.html.erb
@@ -30,8 +30,8 @@
<div class="stats">
Uploaded <span class="utc_date"><strong><%= asset.created_at.iso8601.gsub(/\+.*/,'') %></strong></span>,
listened to <strong><%= asset.listens_count %> times</strong>.
- <% if asset.comments.count > 0 %>
- <br/>Commented on <strong><%= pluralize asset.comments.public.size, 'times' %></strong>.
+ <% if asset.comments_count > 0 %>
+ <br/>Commented on <strong><%= pluralize asset.comments_count, 'times' %></strong>.
<% end %>
<% if asset.favorites_count > 0 %>
Favorited by <strong><%= pluralize asset.favorites_count, 'alonetoner' %></strong>.
Please sign in to comment.
Something went wrong with that request. Please try again.