]> source.dussan.org Git - redmine.git/commitdiff
Use .distinct instead of .uniq.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 14 Jul 2016 07:15:13 +0000 (07:15 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 14 Jul 2016 07:15:13 +0000 (07:15 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@15654 e93f8b46-1217-0410-a6f0-8f06a7374b81

14 files changed:
app/controllers/versions_controller.rb
app/models/issue_status.rb
app/models/journal.rb
app/models/member.rb
app/models/project.rb
app/models/repository.rb
app/models/tracker.rb
app/models/user.rb
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
lib/redmine/helpers/gantt.rb
lib/redmine/nested_set/issue_nested_set.rb
test/integration/issues_test.rb
test/unit/project_members_inheritance_test.rb
test/unit/project_test.rb

index fa99951981d602ee348cd1047cabbd7913827c48..e1684e3cf34eb18418ae8b7520a000c43a228957 100644 (file)
@@ -38,7 +38,7 @@ class VersionsController < ApplicationController
 
         @versions = @project.shared_versions.preload(:custom_values)
         @versions += @project.rolled_up_versions.visible.preload(:custom_values) if @with_subprojects
-        @versions = @versions.uniq.sort
+        @versions = @versions.to_a.uniq.sort
         unless params[:completed]
           @completed_versions = @versions.select(&:completed?)
           @versions -= @completed_versions
index 31c0f031caa7a91440979e40cb05d0b7943fdbdb..553c46bc521043996471fa191302e7389f0a0128 100644 (file)
@@ -66,7 +66,7 @@ class IssueStatus < ActiveRecord::Base
         end
       end
 
-      scope.uniq.to_a.sort
+      scope.distinct.to_a.sort
     else
       []
     end
index d65034c567afbe9e366efe3bd81068202b07f2fc..3f1a349528c332087ff9c1cdd9488f16aaf9556d 100644 (file)
@@ -40,7 +40,7 @@ class Journal < ActiveRecord::Base
                             :scope => preload({:issue => :project}, :user).
                                       joins("LEFT OUTER JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id").
                                       where("#{Journal.table_name}.journalized_type = 'Issue' AND" +
-                                            " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')").uniq
+                                            " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')").distinct
 
   before_create :split_private_notes
   after_create :send_notification
index 389684dabcd2816470297c9a7125384423cd261c..0c6a8868eb4e4220f4d21fb241450139437e4f5c 100644 (file)
@@ -19,7 +19,7 @@ class Member < ActiveRecord::Base
   belongs_to :user
   belongs_to :principal, :foreign_key => 'user_id'
   has_many :member_roles, :dependent => :destroy
-  has_many :roles, lambda {uniq}, :through => :member_roles
+  has_many :roles, lambda { distinct }, :through => :member_roles
   belongs_to :project
 
   validates_presence_of :principal, :project
index c48c54855595152be4eb313951899468ea080144..ac204ebc17ba46b46c7b5beee5a0a75da221a223 100644 (file)
@@ -233,11 +233,11 @@ class Project < ActiveRecord::Base
   end
 
   def principals
-    @principals ||= Principal.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).uniq
+    @principals ||= Principal.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).distinct
   end
 
   def users
-    @users ||= User.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).uniq
+    @users ||= User.active.joins(:members).where("#{Member.table_name}.project_id = ?", id).distinct
   end
 
   # Returns the Systemwide and project specific activities
@@ -437,7 +437,7 @@ class Project < ActiveRecord::Base
       joins(projects: :enabled_modules).
       where("#{Project.table_name}.status <> ?", STATUS_ARCHIVED).
       where(:enabled_modules => {:name => 'issue_tracking'}).
-      uniq.
+      distinct.
       sorted
   end
 
@@ -522,7 +522,7 @@ class Project < ActiveRecord::Base
       active.
       joins(:members => :roles).
       where(:type => types, :members => {:project_id => id}, :roles => {:assignable => true}).
-      uniq.
+      distinct.
       sorted
 
     if tracker
index be1ea93d95057ce525761e359932841ef96fa6d2..5f2f118b7257eb615de0959582c251720ea851ac 100644 (file)
@@ -283,7 +283,7 @@ class Repository < ActiveRecord::Base
 
   # Returns an array of committers usernames and associated user_id
   def committers
-    @committers ||= Changeset.where(:repository_id => id).uniq.pluck(:committer, :user_id)
+    @committers ||= Changeset.where(:repository_id => id).distinct.pluck(:committer, :user_id)
   end
 
   # Maps committers username to a user ids
index 5e4a24b5146a31d9770d5c18151d72d4301b3b1a..41db7880477f8f4798124147786397035617729a 100644 (file)
@@ -66,7 +66,7 @@ class Tracker < ActiveRecord::Base
         end
       end
     end
-    joins(:projects).where(condition).uniq
+    joins(:projects).where(condition).distinct
   }
 
   def to_s; name end
@@ -85,7 +85,7 @@ class Tracker < ActiveRecord::Base
     if new_record?
       []
     else
-      @issue_status_ids ||= WorkflowTransition.where(:tracker_id => id).uniq.pluck(:old_status_id, :new_status_id).flatten.uniq
+      @issue_status_ids ||= WorkflowTransition.where(:tracker_id => id).distinct.pluck(:old_status_id, :new_status_id).flatten.uniq
     end
   end
 
index 0fc740520e890becc2ad5bc34d87a9577b139dca..69db922403bb2c62b4898e8f2446bce3055a44f8 100644 (file)
@@ -140,7 +140,7 @@ class User < Principal
   scope :having_mail, lambda {|arg|
     addresses = Array.wrap(arg).map {|a| a.to_s.downcase}
     if addresses.any?
-      joins(:email_addresses).where("LOWER(#{EmailAddress.table_name}.address) IN (?)", addresses).uniq
+      joins(:email_addresses).where("LOWER(#{EmailAddress.table_name}.address) IN (?)", addresses).distinct
     else
       none
     end
index be89071889918f774515e5579aea070e798c7f04..3975169c0a0275e746a5ad02617f8747bfe4e48e 100644 (file)
@@ -167,7 +167,7 @@ module Redmine
             scope.
               reorder(searchable_options[:date_column] => :desc, :id => :desc).
               limit(limit).
-              uniq.
+              distinct.
               pluck(searchable_options[:date_column], :id).
               # converts timestamps to integers for faster sort
               map {|timestamp, id| [timestamp.to_i, id]}
index 683d201a5b42c7db7ebf8e93254fac54f1521249..79902d370d5a0cb414bb6d9ebdb3c718299381ef 100644 (file)
@@ -168,7 +168,7 @@ module Redmine
             joins("LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt").
             where("child.id IN (?)", ids).
             order("#{Project.table_name}.lft ASC").
-            uniq.
+            distinct.
             to_a
         else
           @projects = []
index 932f56351986d1156568c85f55a79010ee44e49d..afbe6b99516865bd55ae9b8b36b7ca81b4011005 100644 (file)
@@ -176,7 +176,7 @@ module Redmine
             reorder(:id).lock.ids
             update_all(:root_id => nil, :lft => nil, :rgt => nil)
             where(:parent_id => nil).update_all(["root_id = id, lft = ?, rgt = ?", 1, 2])
-            roots_with_children = joins("JOIN #{table_name} parent ON parent.id = #{table_name}.parent_id AND parent.id = parent.root_id").uniq.pluck("parent.id")
+            roots_with_children = joins("JOIN #{table_name} parent ON parent.id = #{table_name}.parent_id AND parent.id = parent.root_id").distinct.pluck("parent.id")
             roots_with_children.each do |root_id|
               rebuild_nodes(root_id)
             end
index 5cafcda4b65c3a400a550fee100fc1e0d972b8b5..76a417c928f52d0a95d22b67ac59055d0e97dc6a 100644 (file)
@@ -172,7 +172,7 @@ class IssuesTest < Redmine::IntegrationTest
   def test_issue_with_user_custom_field
     @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
     Role.anonymous.add_permission! :add_issues, :edit_issues
-    users = Project.find(1).users.uniq.sort
+    users = Project.find(1).users.sort
     tester = users.first
 
     # Issue form
index 43f52d832ffa59dc80b4afbff22af36c5f5dd0d4..74b7987749c7579e65a68e58fbeb9c3c7e614baa 100644 (file)
@@ -242,7 +242,7 @@ class ProjectMembersInheritanceTest < ActiveSupport::TestCase
 
       member = project.reload.memberships.detect {|m| m.principal == user}
       assert_not_nil member
-      assert_equal [1, 2, 3], member.roles.uniq.sort.map(&:id)
+      assert_equal [1, 2, 3], member.roles.map(&:id).uniq.sort
     end
   end
 
@@ -258,7 +258,7 @@ class ProjectMembersInheritanceTest < ActiveSupport::TestCase
 
       member = project.reload.memberships.detect {|m| m.principal == user}
       assert_not_nil member
-      assert_equal [1, 2, 3], member.roles.uniq.sort.map(&:id)
+      assert_equal [1, 2, 3], member.roles.map(&:id).uniq.sort
     end
   end
 end
index 5c305f7bf6213034a51602d1f7d106654c011be5..9a0d9bdd92d0bd921f994b8dc3c558032da4ee55 100644 (file)
@@ -992,12 +992,12 @@ class ProjectTest < ActiveSupport::TestCase
     assert_include 'closed', p.css_classes.split
   end
 
-  def test_combination_of_visible_and_uniq_scopes_in_case_anonymous_group_has_memberships_should_not_error
+  def test_combination_of_visible_and_distinct_scopes_in_case_anonymous_group_has_memberships_should_not_error
     project = Project.find(1)
     member = Member.create!(:project => project, :principal => Group.anonymous, :roles => [Role.generate!])
     project.members << member
     assert_nothing_raised do
-      Project.uniq.visible.to_a
+      Project.distinct.visible.to_a
     end
   end
 end