gitlab-org--gitlab-foss/app/controllers/explore/projects_controller.rb
Yorick Peterse c1f9403e45
Use Prev/Next pagination for exploring projects
This changes the pagination of the "Explore" pages so they use a simpler
pagination system that only shows "Prev" and "Next" buttons. This
removes the need for getting the total number of rows to display, a
process that can easily take up to 2 seconds when browsing through a
large list of projects.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/27390
2017-08-14 13:53:42 +02:00

58 lines
1.3 KiB
Ruby

class Explore::ProjectsController < Explore::ApplicationController
include ParamsBackwardCompatibility
before_action :set_non_archived_param
def index
params[:sort] ||= 'latest_activity_desc'
@sort = params[:sort]
@projects = load_projects
respond_to do |format|
format.html
format.json do
render json: {
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
}
end
end
end
def trending
params[:trending] = true
@sort = params[:sort]
@projects = load_projects
respond_to do |format|
format.html
format.json do
render json: {
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
}
end
end
end
def starred
@projects = load_projects.reorder('star_count DESC')
respond_to do |format|
format.html
format.json do
render json: {
html: view_to_html_string("dashboard/projects/_projects", locals: { projects: @projects })
}
end
end
end
private
def load_projects
ProjectsFinder.new(current_user: current_user, params: params)
.execute
.includes(:route, namespace: :route)
.page(params[:page])
.without_count
end
end