Merge pull request #198 from AyuntamientoMadrid/performance
adds eager loading to avoid N+1 queries
This commit is contained in:
@@ -5,7 +5,7 @@ class DebatesController < ApplicationController
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@debates = Debate.search(params)
|
||||
@debates = Debate.includes(:tags).search(params)
|
||||
set_debate_votes(@debates)
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ class WelcomeController < ApplicationController
|
||||
skip_authorization_check
|
||||
|
||||
def index
|
||||
@featured_debates = Debate.limit(9)
|
||||
@featured_debates = Debate.includes(:tags).limit(9)
|
||||
set_debate_votes(@featured_debates)
|
||||
end
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ class Comment < ActiveRecord::Base
|
||||
belongs_to :commentable, polymorphic: true
|
||||
belongs_to :user
|
||||
|
||||
default_scope { includes(:user) }
|
||||
scope :recent, -> { order(id: :desc) }
|
||||
|
||||
def self.build(commentable, user, body)
|
||||
|
||||
@@ -18,6 +18,7 @@ class User < ActiveRecord::Base
|
||||
|
||||
accepts_nested_attributes_for :organization
|
||||
|
||||
default_scope { includes(:organization) }
|
||||
scope :administrators, -> { joins(:administrators) }
|
||||
scope :moderators, -> { joins(:moderator) }
|
||||
scope :organizations, -> { joins(:organization) }
|
||||
|
||||
Reference in New Issue
Block a user