]> source.dussan.org Git - redmine.git/commitdiff
Get version ids with a single query (was n+1).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 2 Dec 2014 20:32:09 +0000 (20:32 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 2 Dec 2014 20:32:09 +0000 (20:32 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13694 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb

index 2bd69d846ded39fdb7728e6d9c6084a56a5188ca..961fb5bfcd9c5588a424e76e4a1caff74231fc7c 100644 (file)
@@ -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