Commit f9c87101 authored by jplang's avatar jplang

Use .distinct instead of .uniq.

git-svn-id: https://svn.redmine.org/redmine/trunk@15654 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 0fe80ac4
......@@ -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
......
......@@ -66,7 +66,7 @@ class IssueStatus < ActiveRecord::Base
end
end
scope.uniq.to_a.sort
scope.distinct.to_a.sort
else
[]
end
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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]}
......
......@@ -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 = []
......
......@@ -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
......
......@@ -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
......
......@@ -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
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment