Skip to content
Snippets Groups Projects

[WIP] Moves the stage and ref from the table in a ci commit build to a plain one line text

Closed Tiago Botelho requested to merge tiagonbotelho/gitlab-ce:ci-commit into master
2 files
+ 24
1
Compare changes
  • Side-by-side
  • Inline
Files
2
  • 2ddbf7c4
    The OR condition for source_project_id/target_project_id leads to a
    query plan that performs rather poorly on PostgreSQL due to the use of
    sub-queries. Because Rails offers no easy alternative for this
    particular problem we're forced to using a UNION for both conditions.
    The resulting query performs much faster than just using an OR.
@@ -135,7 +135,6 @@ class MergeRequest < ActiveRecord::Base
@@ -135,7 +135,6 @@ class MergeRequest < ActiveRecord::Base
scope :by_branch, ->(branch_name) { where("(source_branch LIKE :branch) OR (target_branch LIKE :branch)", branch: branch_name) }
scope :by_branch, ->(branch_name) { where("(source_branch LIKE :branch) OR (target_branch LIKE :branch)", branch: branch_name) }
scope :cared, ->(user) { where('assignee_id = :user OR author_id = :user', user: user.id) }
scope :cared, ->(user) { where('assignee_id = :user OR author_id = :user', user: user.id) }
scope :by_milestone, ->(milestone) { where(milestone_id: milestone) }
scope :by_milestone, ->(milestone) { where(milestone_id: milestone) }
scope :in_projects, ->(project_ids) { where("source_project_id in (:project_ids) OR target_project_id in (:project_ids)", project_ids: project_ids) }
scope :of_projects, ->(ids) { where(target_project_id: ids) }
scope :of_projects, ->(ids) { where(target_project_id: ids) }
scope :merged, -> { with_state(:merged) }
scope :merged, -> { with_state(:merged) }
scope :closed_and_merged, -> { with_states(:closed, :merged) }
scope :closed_and_merged, -> { with_states(:closed, :merged) }
@@ -161,6 +160,24 @@ def self.link_reference_pattern
@@ -161,6 +160,24 @@ def self.link_reference_pattern
super("merge_requests", /(?<merge_request>\d+)/)
super("merge_requests", /(?<merge_request>\d+)/)
end
end
 
# Returns all the merge requests from an ActiveRecord:Relation.
 
#
 
# This method uses a UNION as it usually operates on the result of
 
# ProjectsFinder#execute. PostgreSQL in particular doesn't always like queries
 
# using multiple sub-queries especially when combined with an OR statement.
 
# UNIONs on the other hand perform much better in these cases.
 
#
 
# relation - An ActiveRecord::Relation that returns a list of Projects.
 
#
 
# Returns an ActiveRecord::Relation.
 
def self.in_projects(relation)
 
source = where(source_project_id: relation).select(:id)
 
target = where(target_project_id: relation).select(:id)
 
union = Gitlab::SQL::Union.new([source, target])
 
 
where("merge_requests.id IN (#{union.to_sql})")
 
end
 
def to_reference(from_project = nil)
def to_reference(from_project = nil)
reference = "#{self.class.reference_prefix}#{iid}"
reference = "#{self.class.reference_prefix}#{iid}"
Loading