summaryrefslogtreecommitdiff
path: root/app/controllers/groups/milestones_controller.rb
diff options
context:
space:
mode:
authorMarin Jankovski <marin@gitlab.com>2014-07-04 11:57:24 +0200
committerMarin Jankovski <marin@gitlab.com>2014-07-04 11:57:24 +0200
commit3b5722bca9e7e853c1428631ae21c600e17ef4a5 (patch)
treedaa41aa281331e4ad535521f4cf235ac75d1d98b /app/controllers/groups/milestones_controller.rb
parent83fd03f2ddb6b2fb2088bb9b3945fe13afb91320 (diff)
downloadgitlab-ce-3b5722bca9e7e853c1428631ae21c600e17ef4a5.tar.gz
Improve performance, ordering and pagination for group milestones.
Diffstat (limited to 'app/controllers/groups/milestones_controller.rb')
-rw-r--r--app/controllers/groups/milestones_controller.rb22
1 files changed, 12 insertions, 10 deletions
diff --git a/app/controllers/groups/milestones_controller.rb b/app/controllers/groups/milestones_controller.rb
index 8dde8e91468..860d8e03922 100644
--- a/app/controllers/groups/milestones_controller.rb
+++ b/app/controllers/groups/milestones_controller.rb
@@ -4,22 +4,22 @@ class Groups::MilestonesController < ApplicationController
before_filter :authorize_group_milestone!, only: :update
def index
- project_milestones = Milestone.where(project_id: group.projects)
+ project_milestones = case params[:status]
+ when 'all'; status
+ when 'closed'; status('closed')
+ else status('active')
+ end
@group_milestones = Milestones::GroupService.new(project_milestones).execute
- @group_milestones = case params[:status]
- when 'all'; @group_milestones
- when 'closed'; status('closed')
- else status('active')
- end
+ @group_milestones = Kaminari.paginate_array(@group_milestones).page(params[:page]).per(30)
end
def show
- project_milestones = Milestone.where(project_id: group.projects)
+ project_milestones = Milestone.where(project_id: group.projects).order("due_date ASC")
@group_milestone = Milestones::GroupService.new(project_milestones).milestone(title)
end
def update
- project_milestones = Milestone.where(project_id: group.projects)
+ project_milestones = Milestone.where(project_id: group.projects).order("due_date ASC")
@group_milestones = Milestones::GroupService.new(project_milestones).milestone(title)
@group_milestones.milestones.each do |milestone|
@@ -44,8 +44,10 @@ class Groups::MilestonesController < ApplicationController
params[:title]
end
- def status(state)
- @group_milestones.map{ |milestone| next if milestone.state != state; milestone }.compact
+ def status(state = nil)
+ conditions = { project_id: group.projects }
+ conditions.reverse_merge!(state: state) if state
+ Milestone.where(conditions).order("title ASC")
end
def authorize_group_milestone!