Merge pull request #2819 from evazion/opt-favorited-users
Reduce SQL queries on /posts/:id
This commit is contained in:
@@ -44,7 +44,7 @@ class Post < ActiveRecord::Base
|
|||||||
has_many :versions, lambda {order("post_versions.updated_at ASC, post_versions.id ASC")}, :class_name => "PostVersion", :dependent => :destroy
|
has_many :versions, lambda {order("post_versions.updated_at ASC, post_versions.id ASC")}, :class_name => "PostVersion", :dependent => :destroy
|
||||||
has_many :votes, :class_name => "PostVote", :dependent => :destroy
|
has_many :votes, :class_name => "PostVote", :dependent => :destroy
|
||||||
has_many :notes, :dependent => :destroy
|
has_many :notes, :dependent => :destroy
|
||||||
has_many :comments, lambda {order("comments.id")}, :dependent => :destroy
|
has_many :comments, lambda {includes(:creator, :updater).order("comments.id")}, :dependent => :destroy
|
||||||
has_many :children, lambda {order("posts.id")}, :class_name => "Post", :foreign_key => "parent_id"
|
has_many :children, lambda {order("posts.id")}, :class_name => "Post", :foreign_key => "parent_id"
|
||||||
has_many :disapprovals, :class_name => "PostDisapproval", :dependent => :destroy
|
has_many :disapprovals, :class_name => "PostDisapproval", :dependent => :destroy
|
||||||
has_many :favorites, :dependent => :destroy
|
has_many :favorites, :dependent => :destroy
|
||||||
@@ -965,9 +965,7 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def favorited_users
|
def favorited_users
|
||||||
favorited_user_ids.map {|id| User.find(id)}.select do |x|
|
User.find(favorited_user_ids).reject(&:hide_favorites?)
|
||||||
!x.hide_favorites?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def favorite_groups(active_id=nil)
|
def favorite_groups(active_id=nil)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<% if CurrentUser.is_moderator? || !comment.is_deleted? %>
|
<% if CurrentUser.is_moderator? || !comment.is_deleted? %>
|
||||||
<a name="comment-<%= comment.id %>"></a>
|
<a name="comment-<%= comment.id %>"></a>
|
||||||
<article class="comment" data-post-id="<%= comment.post_id %>" data-comment-id="<%= comment.id %>" data-score="<%= comment.score %>" data-creator="<%= comment.creator.name %>" data-is-sticky="<%= comment.is_sticky %>">
|
<article class="comment" data-post-id="<%= comment.post_id %>" data-comment-id="<%= comment.id %>" data-score="<%= comment.score %>" data-creator="<%= comment.creator_name %>" data-is-sticky="<%= comment.is_sticky %>">
|
||||||
<div class="author">
|
<div class="author">
|
||||||
<h1>
|
<h1>
|
||||||
<%= link_to_user comment.creator %>
|
<%= link_to_user comment.creator %>
|
||||||
|
|||||||
Reference in New Issue
Block a user