diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-07-14 07:15:13 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-07-14 07:15:13 +0000 |
commit | d2f7e31951d0e150df9cfd6da7d91d855f734d5f (patch) | |
tree | 35dfd4e7ff86f66c9eacb5bec14c63e920913896 | |
parent | e58e676b7c15bb3f837f660f857d8e2a3e35f233 (diff) | |
download | redmine-d2f7e31951d0e150df9cfd6da7d91d855f734d5f.tar.gz redmine-d2f7e31951d0e150df9cfd6da7d91d855f734d5f.zip |
Use .distinct instead of .uniq.
git-svn-id: http://svn.redmine.org/redmine/trunk@15654 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/versions_controller.rb | 2 | ||||
-rw-r--r-- | app/models/issue_status.rb | 2 | ||||
-rw-r--r-- | app/models/journal.rb | 2 | ||||
-rw-r--r-- | app/models/member.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 8 | ||||
-rw-r--r-- | app/models/repository.rb | 2 | ||||
-rw-r--r-- | app/models/tracker.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb | 2 | ||||
-rw-r--r-- | lib/redmine/helpers/gantt.rb | 2 | ||||
-rw-r--r-- | lib/redmine/nested_set/issue_nested_set.rb | 2 | ||||
-rw-r--r-- | test/integration/issues_test.rb | 2 | ||||
-rw-r--r-- | test/unit/project_members_inheritance_test.rb | 4 | ||||
-rw-r--r-- | test/unit/project_test.rb | 4 |
14 files changed, 20 insertions, 20 deletions
diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index fa9995198..e1684e3cf 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -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 diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index 31c0f031c..553c46bc5 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -66,7 +66,7 @@ class IssueStatus < ActiveRecord::Base end end - scope.uniq.to_a.sort + scope.distinct.to_a.sort else [] end diff --git a/app/models/journal.rb b/app/models/journal.rb index d65034c56..3f1a34952 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -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 diff --git a/app/models/member.rb b/app/models/member.rb index 389684dab..0c6a8868e 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index c48c54855..ac204ebc1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/models/repository.rb b/app/models/repository.rb index be1ea93d9..5f2f118b7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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 diff --git a/app/models/tracker.rb b/app/models/tracker.rb index 5e4a24b51..41db78804 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 0fc740520..69db92240 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb b/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb index be8907188..3975169c0 100644 --- a/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb +++ b/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb @@ -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]} diff --git a/lib/redmine/helpers/gantt.rb b/lib/redmine/helpers/gantt.rb index 683d201a5..79902d370 100644 --- a/lib/redmine/helpers/gantt.rb +++ b/lib/redmine/helpers/gantt.rb @@ -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 = [] diff --git a/lib/redmine/nested_set/issue_nested_set.rb b/lib/redmine/nested_set/issue_nested_set.rb index 932f56351..afbe6b995 100644 --- a/lib/redmine/nested_set/issue_nested_set.rb +++ b/lib/redmine/nested_set/issue_nested_set.rb @@ -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 diff --git a/test/integration/issues_test.rb b/test/integration/issues_test.rb index 5cafcda4b..76a417c92 100644 --- a/test/integration/issues_test.rb +++ b/test/integration/issues_test.rb @@ -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 diff --git a/test/unit/project_members_inheritance_test.rb b/test/unit/project_members_inheritance_test.rb index 43f52d832..74b798774 100644 --- a/test/unit/project_members_inheritance_test.rb +++ b/test/unit/project_members_inheritance_test.rb @@ -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 diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 5c305f7bf..9a0d9bdd9 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -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 |