Skip to content

Global Milestones page loads all milestones into memory

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

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:

  1. Require sending a lot of data over the wire
  2. The data queried will be loaded into the PG buffer caches, even if it won't be displayed until page 100
  3. All this data will be loaded into memory
  4. 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:

  1. Only load 20 rows at a time
  2. Paginate this data using Kaminari, without using Kaminari.paginate_array
  3. 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 🤖 GitLab Bot 🤖