1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-01-02 13:49:42 +00:00

Preload project when possible (#5754).

git-svn-id: http://svn.redmine.org/redmine/trunk@15314 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2016-04-09 07:54:43 +00:00
parent 14234eae39
commit 933dc946d4

View File

@ -131,7 +131,12 @@ class WatchersController < ApplicationController
klass = Object.const_get(params[:object_type].camelcase) rescue nil
return unless klass && klass.respond_to?('watched_by')
objects = klass.where(:id => Array.wrap(params[:object_id])).to_a
scope = klass.where(:id => Array.wrap(params[:object_id]))
if klass.reflect_on_association(:project)
scope = scope.preload(:project => :enabled_modules)
end
objects = scope.to_a
raise Unauthorized if objects.any? do |w|
if w.respond_to?(:visible?)
!w.visible?