BigW Consortium Gitlab

Commit a056dfa9 by Rubén Dávila

Refactor GlobalMilestone queries.

Make methods return ActiveRecord Relations instead of Arrays.
parent 3231ea10
......@@ -29,6 +29,7 @@ module Issuable
scope :assigned, -> { where("assignee_id IS NOT NULL") }
scope :unassigned, -> { where("assignee_id IS NULL") }
scope :of_projects, ->(ids) { where(project_id: ids) }
scope :of_milestones, ->(ids) { where(milestone_id: ids) }
scope :opened, -> { with_state(:opened, :reopened) }
scope :only_opened, -> { with_state(:opened) }
scope :only_reopened, -> { with_state(:reopened) }
......
......@@ -28,27 +28,27 @@ class GlobalMilestone
end
def projects
milestones.map { |milestone| milestone.project }
@projects ||= Project.for_milestones(milestones.map(&:id))
end
def issue_count
milestones.map { |milestone| milestone.issues.count }.sum
def issues_count
issues.count
end
def merge_requests_count
milestones.map { |milestone| milestone.merge_requests.count }.sum
merge_requests.count
end
def open_items_count
milestones.map { |milestone| milestone.open_items_count }.sum
opened_issues.count + opened_merge_requests.count
end
def closed_items_count
milestones.map { |milestone| milestone.closed_items_count }.sum
closed_issues.count + closed_merge_requests.count
end
def total_items_count
milestones.map { |milestone| milestone.total_items_count }.sum
issues_count + merge_requests_count
end
def percent_complete
......@@ -76,11 +76,11 @@ class GlobalMilestone
end
def issues
@issues ||= milestones.map(&:issues).flatten.group_by(&:state)
@issues ||= Issue.of_milestones(milestones.map(&:id))
end
def merge_requests
@merge_requests ||= milestones.map(&:merge_requests).flatten.group_by(&:state)
@merge_requests ||= MergeRequest.of_milestones(milestones.map(&:id))
end
def participants
......@@ -88,19 +88,19 @@ class GlobalMilestone
end
def opened_issues
issues.values_at("opened", "reopened").compact.flatten
issues.opened
end
def closed_issues
issues['closed']
issues.closed
end
def opened_merge_requests
merge_requests.values_at("opened", "reopened").compact.flatten
merge_requests.opened
end
def closed_merge_requests
merge_requests.values_at("closed", "merged", "locked").compact.flatten
merge_requests.with_states(:closed, :merged, :locked)
end
def complete?
......
......@@ -139,7 +139,6 @@ class MergeRequest < ActiveRecord::Base
scope :of_projects, ->(ids) { where(target_project_id: ids) }
scope :opened, -> { with_states(:opened, :reopened) }
scope :merged, -> { with_state(:merged) }
scope :closed, -> { with_state(:closed) }
scope :closed_and_merged, -> { with_states(:closed, :merged) }
scope :join_project, -> { joins(:target_project) }
......
......@@ -215,6 +215,7 @@ class Project < ActiveRecord::Base
scope :public_only, -> { where(visibility_level: Project::PUBLIC) }
scope :public_and_internal_only, -> { where(visibility_level: Project.public_and_internal_levels) }
scope :non_archived, -> { where(archived: false) }
scope :for_milestones, ->(ids) { joins(:milestones).where('milestones.id' => ids) }
state_machine :import_status, initial: :none do
event :import_start do
......
......@@ -8,7 +8,7 @@
.row
.col-sm-6
= link_to issues_dashboard_path(milestone_title: milestone.title) do
= pluralize milestone.issue_count, 'Issue'
= pluralize milestone.issues_count, 'Issue'
&middot;
= link_to merge_requests_dashboard_path(milestone_title: milestone.title) do
= pluralize milestone.merge_requests_count, 'Merge Request'
......
......@@ -52,7 +52,7 @@
%li.active
= link_to '#tab-issues', 'data-toggle' => 'tab' do
Issues
%span.badge= @milestone.issue_count
%span.badge= @milestone.issues_count
%li
= link_to '#tab-merge-requests', 'data-toggle' => 'tab' do
Merge Requests
......
......@@ -8,7 +8,7 @@
.row
.col-sm-6
= link_to issues_group_path(@group, milestone_title: milestone.title) do
= pluralize milestone.issue_count, 'Issue'
= pluralize milestone.issues_count, 'Issue'
&middot;
= link_to merge_requests_group_path(@group, milestone_title: milestone.title) do
= pluralize milestone.merge_requests_count, 'Merge Request'
......
......@@ -58,7 +58,7 @@
%li.active
= link_to '#tab-issues', 'data-toggle' => 'tab' do
Issues
%span.badge= @milestone.issue_count
%span.badge= @milestone.issues_count
%li
= link_to '#tab-merge-requests', 'data-toggle' => 'tab' do
Merge Requests
......
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