Commit f40d8c1c authored by Etienne Baqué's avatar Etienne Baqué

Simplified the sql queries used in issuable scopes

parent ef23d0a0
......@@ -100,8 +100,8 @@ module Issuable
scope :of_milestones, ->(ids) { where(milestone_id: ids) }
scope :any_milestone, -> { where('milestone_id IS NOT NULL') }
scope :with_milestone, ->(title) { left_joins_milestones.where(milestones: { title: title }) }
scope :any_release, -> { left_joins_milestones_joins_releases }
scope :with_release, -> (tag) { left_joins_milestones_joins_releases.where( milestones: { releases: { tag: tag } } ) }
scope :any_release, -> { joins_milestone_releases }
scope :with_release, -> (tag) { joins_milestone_releases.where( milestones: { releases: { tag: tag } } ) }
scope :opened, -> { with_state(:opened) }
scope :only_opened, -> { with_state(:opened) }
scope :closed, -> { with_state(:closed) }
......@@ -124,16 +124,13 @@ module Issuable
scope :order_milestone_due_asc, -> { left_joins_milestones.reorder(Arel.sql('milestones.due_date IS NULL, milestones.id IS NULL, milestones.due_date ASC')) }
scope :without_release, -> do
left_joins_milestones
.joins("LEFT OUTER JOIN milestone_releases ON milestones.id = milestone_releases.milestone_id")
joins("LEFT OUTER JOIN milestone_releases ON #{table_name}.milestone_id = milestone_releases.milestone_id")
.where('milestone_releases.release_id IS NULL')
end
scope :left_joins_milestones_joins_releases, -> do
left_joins_milestones
.joins("JOIN milestone_releases ON milestones.id = milestone_releases.milestone_id
JOIN releases ON milestone_releases.release_id = releases.id")
.where('milestone_releases.release_id IS NOT NULL').distinct
scope :joins_milestone_releases, -> do
joins("JOIN milestone_releases ON issues.milestone_id = milestone_releases.milestone_id
JOIN releases ON milestone_releases.release_id = releases.id").distinct
end
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }
......
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