]> source.dussan.org Git - redmine.git/commitdiff
remove unneeded "references" of joins
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Fri, 24 Oct 2014 02:18:45 +0000 (02:18 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Fri, 24 Oct 2014 02:18:45 +0000 (02:18 +0000)
"references" is needed for includes, but not needed for joins.

git-svn-id: http://svn.redmine.org/redmine/trunk@13501 e93f8b46-1217-0410-a6f0-8f06a7374b81

15 files changed:
app/controllers/boards_controller.rb
app/helpers/my_helper.rb
app/models/board.rb
app/models/changeset.rb
app/models/document.rb
app/models/group.rb
app/models/issue.rb
app/models/issue_query.rb
app/models/journal.rb
app/models/message.rb
app/models/news.rb
app/models/project.rb
app/models/time_entry.rb
app/models/version.rb
test/unit/query_test.rb

index 04bdb56c0323d0211c6d12d3440e91b02abb48ca..c1ac10c4ffee4cd0329d10333427c25a3d26b9bf 100644 (file)
@@ -46,7 +46,6 @@ class BoardsController < ApplicationController
         @topics =  @board.topics.
           reorder("#{Message.table_name}.sticky DESC").
           joins("LEFT OUTER JOIN #{Message.table_name} last_replies_messages ON last_replies_messages.id = #{Message.table_name}.last_reply_id").
-          references(:last_reply).
           limit(@topic_pages.per_page).
           offset(@topic_pages.offset).
           order(sort_clause).
index 5917f26ec6a5034f3821f14bef571944eda459b8..5e826886abc8ff07691782089d9ce1c4078fe86d 100644 (file)
@@ -69,7 +69,6 @@ module MyHelper
     TimeEntry.
       where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, Date.today - 6, Date.today).
       joins(:activity, :project, {:issue => [:tracker, :status]}).
-      references(:activity, :project, {:issue => [:tracker, :status]}).
       order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC").
       to_a
   end
index 7e2507d8bdf9f6246210666ec27f1720a5033a8c..70d3cb2e5cdc7894c6132841fe738c6076deb2e9 100644 (file)
@@ -32,7 +32,6 @@ class Board < ActiveRecord::Base
 
   scope :visible, lambda {|*args|
     joins(:project).
-    references(:project).
     where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
   }
 
index d752441668757231c4d21f2d6dfcc10ca8b9cfd6..c54ad0bc3ae2f1be6808f531e1035ace6b8a493e 100644 (file)
@@ -50,7 +50,6 @@ class Changeset < ActiveRecord::Base
 
   scope :visible, lambda {|*args|
     joins(:repository => :project).
-    references(:repository => :project).
     where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))
   }
 
index 00530131aa86d38bda7681e45fb84598cc356de6..70e3c9b0135c98d7c1f6a63437b30df7a2786923 100644 (file)
@@ -36,7 +36,6 @@ class Document < ActiveRecord::Base
 
   scope :visible, lambda {|*args|
     joins(:project).
-    references(:project).
     where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
   }
 
index b9d4d9ef4d3cc1125d90775b6ac154de1bca9837..a7a17edb8996ceb399b38dd7b28fc723ea8aa104 100644 (file)
@@ -83,7 +83,6 @@ class Group < Principal
     members.each do |member|
       MemberRole.
         joins(:member).
-        references(:member).
         where("#{Member.table_name}.user_id = ? AND #{MemberRole.table_name}.inherited_from IN (?)", user.id, member.member_role_ids).
         each(&:destroy)
     end
index d50d755d4f6539dbc58938bf1713d69d0b2b6541..8bdfda836ca1ab35129fe6f447917b79edce7fd4 100644 (file)
@@ -85,14 +85,12 @@ class Issue < ActiveRecord::Base
   scope :open, lambda {|*args|
     is_closed = args.size > 0 ? !args.first : false
     joins(:status).
-    references(:status).
     where("#{IssueStatus.table_name}.is_closed = ?", is_closed)
   }
 
   scope :recently_updated, lambda { order("#{Issue.table_name}.updated_on DESC") }
   scope :on_active_project, lambda {
     joins(:project).
-    references(:project).
     where("#{Project.table_name}.status = ?", Project::STATUS_ACTIVE)
   }
   scope :fixed_version, lambda {|versions|
@@ -891,11 +889,9 @@ class Issue < ActiveRecord::Base
       issue_ids = issues.map(&:id)
       # Relations with issue_from in given issues and visible issue_to
       relations_from = IssueRelation.joins(:issue_to => :project).
-                         references(:issue_to => :project).
                          where(visible_condition(user)).where(:issue_from_id => issue_ids).to_a
       # Relations with issue_to in given issues and visible issue_from
       relations_to = IssueRelation.joins(:issue_from => :project).
-                         references(:issue_from => :project).
                          where(visible_condition(user)).
                          where(:issue_to_id => issue_ids).to_a
       issues.each do |issue|
@@ -1440,7 +1436,6 @@ class Issue < ActiveRecord::Base
     # Only need to update issues with a fixed_version from
     # a different project and that is not systemwide shared
     Issue.joins(:project, :fixed_version).
-      references(:version, :fixed_version).
       where("#{Issue.table_name}.fixed_version_id IS NOT NULL" +
         " AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" +
         " AND #{Version.table_name}.sharing <> 'system'").
index 9ca0f3077794be4645528b2b842539775478c858..15c49c5d6691b42e5a5e1a6d56e4b19bfcefa3ed 100644 (file)
@@ -46,7 +46,6 @@ class IssueQuery < Query
     user = args.shift || User.current
     base = Project.allowed_to_condition(user, :view_issues, *args)
     scope = joins("LEFT OUTER JOIN #{Project.table_name} ON #{table_name}.project_id = #{Project.table_name}.id").
-      references(:project).
       where("#{table_name}.project_id IS NULL OR (#{base})")
 
     if user.admin?
index 543da42b865b887a8f1e1267a976f1d4f48d7ea2..770e985857536ec5ea917c0a49c206c1b5938c81 100644 (file)
@@ -46,7 +46,6 @@ class Journal < ActiveRecord::Base
   scope :visible, lambda {|*args|
     user = args.shift || User.current
     joins(:issue => :project).
-    references(:project).
       where(Issue.visible_condition(user, *args)).
       where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
   }
index a5540d95354be0d227d9723aec6bf69d1a553d19..dee5a5b626e0e80f4595f2ae4ad6589c77800aec 100644 (file)
@@ -50,7 +50,6 @@ class Message < ActiveRecord::Base
 
   scope :visible, lambda {|*args|
     joins(:board => :project).
-    references(:board => :project).
     where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
   }
 
index 59411bd44e47be03ce915c34b8fd84c284754e69..65a22c66f23324c7083a07c0b7cce3c21c225411 100644 (file)
@@ -39,7 +39,6 @@ class News < ActiveRecord::Base
 
   scope :visible, lambda {|*args|
     joins(:project).
-    references([:author, :project]).
     where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
   }
 
index 92bbf0e88a0f22b5a1a62ec3a0b1c98262507bd3..89d4a52974d291f587b48385ff32451cb179cec7 100644 (file)
@@ -30,12 +30,10 @@ class Project < ActiveRecord::Base
   has_many :time_entry_activities
   has_many :members,
            lambda { joins(:principal, :roles).
-                    references(:principal, :roles).
                     where("#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}") }
   has_many :memberships, :class_name => 'Member'
   has_many :member_principals,
            lambda { joins(:principal).
-                    references(:principal).
                     where("#{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}")},
     :class_name => 'Member'
   has_many :enabled_modules, :dependent => :delete_all
@@ -438,7 +436,6 @@ class Project < ActiveRecord::Base
     @rolled_up_trackers ||=
       Tracker.
         joins(:projects).
-        references(:project).
         joins("JOIN #{EnabledModule.table_name} ON #{EnabledModule.table_name}.project_id = #{Project.table_name}.id AND #{EnabledModule.table_name}.name = 'issue_tracking'").
         select("DISTINCT #{Tracker.table_name}.*").
         where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> #{STATUS_ARCHIVED}", lft, rgt).
@@ -462,7 +459,6 @@ class Project < ActiveRecord::Base
     @rolled_up_versions ||=
       Version.
         joins(:project).
-        references(:project).
         where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED)
   end
 
@@ -471,7 +467,6 @@ class Project < ActiveRecord::Base
     if new_record?
       Version.
         joins(:project).
-        references(:project).
         preload(:project).
         where("#{Project.table_name}.status <> ? AND #{Version.table_name}.sharing = 'system'", STATUS_ARCHIVED)
     else
@@ -479,7 +474,6 @@ class Project < ActiveRecord::Base
         r = root? ? self : root
         Version.
           joins(:project).
-          references(:project).
           preload(:project).
           where("#{Project.table_name}.id = #{id}" +
                   " OR (#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED} AND (" +
index 80112308a77b65560ccb15b1deeab00f14fa13d5..240df755658e9e931d31477cba7be5c288a69faa 100644 (file)
@@ -46,17 +46,14 @@ class TimeEntry < ActiveRecord::Base
 
   scope :visible, lambda {|*args|
     joins(:project).
-    references(:project).
     where(Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args))
   }
   scope :on_issue, lambda {|issue|
     joins(:issue).
-    references(:issue).
     where("#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}")
   }
   scope :on_project, lambda {|project, include_subprojects|
     joins(:project).
-    references(:project).
     where(project.project_condition(include_subprojects))
   }
   scope :spent_between, lambda {|from, to|
index 878c611edbf74c2030102ee69a0d63ad98ab38eb..214a987adbba3a5cfdd444ec3f6f6e788ca2a94b 100644 (file)
@@ -39,7 +39,6 @@ class Version < ActiveRecord::Base
   scope :open, lambda { where(:status => 'open') }
   scope :visible, lambda {|*args|
     joins(:project).
-    references(:project).
     where(Project.allowed_to_condition(args.first || User.current, :view_issues))
   }
 
index 692fbdbbe60571e2e107065f5dd5bb536e9e3d86..b46da14050bab479d0455d5de1b1cb842cec12dd 100644 (file)
@@ -103,7 +103,7 @@ class QueryTest < ActiveSupport::TestCase
   def find_issues_with_query(query)
     Issue.joins(:status, :tracker, :project, :priority).where(
          query.statement
-       ).references([:assigned_to, :status, :tracker, :project, :priority]).to_a
+       ).to_a
   end
 
   def assert_find_issues_with_query_is_successful(query)