Replace deprecated uniq on a Relation with distinct
This commit is contained in:
		
							parent
							
								
									1815aa561a
								
							
						
					
					
						commit
						db80db793f
					
				| 
						 | 
					@ -145,7 +145,7 @@ class Milestone < ActiveRecord::Base
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def participants
 | 
					  def participants
 | 
				
			||||||
    User.joins(assigned_issues: :milestone).where("milestones.id = ?", id).uniq
 | 
					    User.joins(assigned_issues: :milestone).where("milestones.id = ?", id).distinct
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def self.sort_by_attribute(method)
 | 
					  def self.sort_by_attribute(method)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1138,7 +1138,7 @@ class User < ActiveRecord::Base
 | 
				
			||||||
    events = Event.select(:project_id)
 | 
					    events = Event.select(:project_id)
 | 
				
			||||||
      .contributions.where(author_id: self)
 | 
					      .contributions.where(author_id: self)
 | 
				
			||||||
      .where("created_at > ?", Time.now - 1.year)
 | 
					      .where("created_at > ?", Time.now - 1.year)
 | 
				
			||||||
      .uniq
 | 
					      .distinct
 | 
				
			||||||
      .reorder(nil)
 | 
					      .reorder(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Project.where(id: events)
 | 
					    Project.where(id: events)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,8 +24,8 @@ class DeleteMergedBranchesService < BaseService
 | 
				
			||||||
  # rubocop: disable CodeReuse/ActiveRecord
 | 
					  # rubocop: disable CodeReuse/ActiveRecord
 | 
				
			||||||
  def merge_request_branch_names
 | 
					  def merge_request_branch_names
 | 
				
			||||||
    # reorder(nil) is necessary for SELECT DISTINCT because default scope adds an ORDER BY
 | 
					    # reorder(nil) is necessary for SELECT DISTINCT because default scope adds an ORDER BY
 | 
				
			||||||
    source_names = project.origin_merge_requests.opened.reorder(nil).uniq.pluck(:source_branch)
 | 
					    source_names = project.origin_merge_requests.opened.reorder(nil).distinct.pluck(:source_branch)
 | 
				
			||||||
    target_names = project.merge_requests.opened.reorder(nil).uniq.pluck(:target_branch)
 | 
					    target_names = project.merge_requests.opened.reorder(nil).distinct.pluck(:target_branch)
 | 
				
			||||||
    (source_names + target_names).uniq
 | 
					    (source_names + target_names).uniq
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  # rubocop: enable CodeReuse/ActiveRecord
 | 
					  # rubocop: enable CodeReuse/ActiveRecord
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,7 @@ module Labels
 | 
				
			||||||
          group_labels_applied_to_merge_requests
 | 
					          group_labels_applied_to_merge_requests
 | 
				
			||||||
        ])
 | 
					        ])
 | 
				
			||||||
        .reorder(nil)
 | 
					        .reorder(nil)
 | 
				
			||||||
        .uniq
 | 
					        .distinct
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    # rubocop: enable CodeReuse/ActiveRecord
 | 
					    # rubocop: enable CodeReuse/ActiveRecord
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					title: Replace deprecated uniq on a Relation with distinct
 | 
				
			||||||
 | 
					merge_request: 22625
 | 
				
			||||||
 | 
					author: Jasper Maes
 | 
				
			||||||
 | 
					type: other
 | 
				
			||||||
| 
						 | 
					@ -73,7 +73,7 @@ module Gitlab
 | 
				
			||||||
      # re-running the contributed projects query in each union is expensive, so
 | 
					      # re-running the contributed projects query in each union is expensive, so
 | 
				
			||||||
      # use IN(project_ids...) instead. It's the intersection of two users so
 | 
					      # use IN(project_ids...) instead. It's the intersection of two users so
 | 
				
			||||||
      # the list will be (relatively) short
 | 
					      # the list will be (relatively) short
 | 
				
			||||||
      @contributed_project_ids ||= projects.uniq.pluck(:id)
 | 
					      @contributed_project_ids ||= projects.distinct.pluck(:id)
 | 
				
			||||||
      authed_projects = Project.where(id: @contributed_project_ids)
 | 
					      authed_projects = Project.where(id: @contributed_project_ids)
 | 
				
			||||||
        .with_feature_available_for_user(feature, current_user)
 | 
					        .with_feature_available_for_user(feature, current_user)
 | 
				
			||||||
        .reorder(nil)
 | 
					        .reorder(nil)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue