summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-12-02 20:32:09 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-12-02 20:32:09 +0000
commit1059f9a99ec41a8e320d4d66684e65d183270920 (patch)
tree3b7c1197be159600d9d0cebf471142e228750d6b
parent22a9742216ac93de2e7781417c38ad7ba88663a5 (diff)
downloadredmine-1059f9a99ec41a8e320d4d66684e65d183270920.tar.gz
redmine-1059f9a99ec41a8e320d4d66684e65d183270920.zip
Get version ids with a single query (was n+1).
git-svn-id: http://svn.redmine.org/redmine/trunk@13694 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/project.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 2bd69d846..961fb5bfc 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -334,12 +334,13 @@ class Project < ActiveRecord::Base
def archive
# Check that there is no issue of a non descendant project that is assigned
# to one of the project or descendant versions
- v_ids = self_and_descendants.collect {|p| p.version_ids}.flatten
- if v_ids.any? &&
+ version_ids = self_and_descendants.joins(:versions).pluck("#{Version.table_name}.id")
+
+ if version_ids.any? &&
Issue.
includes(:project).
where("#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?", lft, rgt).
- where("#{Issue.table_name}.fixed_version_id IN (?)", v_ids).
+ where(:fixed_version_id => version_ids).
exists?
return false
end