Global Milestones page loads all milestones into memory
The page https://gitlab.com/dashboard/milestones will load all milestones into memory, then paginate them as an array:
def index
respond_to do |format|
format.html do
@milestone_states = GlobalMilestone.states_count(@projects)
@milestones = Kaminari.paginate_array(milestones).page(params[:page]) # <- here
end
format.json do
render json: milestones
end
end
end
This is really bad because given enough milestones this will:
- Require sending a lot of data over the wire
- The data queried will be loaded into the PG buffer caches, even if it won't be displayed until page 100
- All this data will be loaded into memory
- All of this combined means it can take quite a long time to load these pages (e.g. we currently already spend 326 ms in SQL)
This page needs to be fixed so we:
- Only load 20 rows at a time
- Paginate this data using Kaminari, without using
Kaminari.paginate_array
- Don't issue an additional COUNT(*) to get the number of pages, instead re-using the state counters displayed in the tabs at the top (just like we do with issues and MRs)
Edited by Yorick Peterse