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
This commit is contained in:
parent
21a6898b10
commit
c1f9403e45
2
Gemfile
2
Gemfile
|
@ -84,7 +84,7 @@ gem 'rack-cors', '~> 0.4.0', require: 'rack/cors'
|
||||||
gem 'hashie-forbidden_attributes'
|
gem 'hashie-forbidden_attributes'
|
||||||
|
|
||||||
# Pagination
|
# Pagination
|
||||||
gem 'kaminari', '~> 0.17.0'
|
gem 'kaminari', '~> 1.0'
|
||||||
|
|
||||||
# HAML
|
# HAML
|
||||||
gem 'hamlit', '~> 2.6.1'
|
gem 'hamlit', '~> 2.6.1'
|
||||||
|
|
17
Gemfile.lock
17
Gemfile.lock
|
@ -419,9 +419,18 @@ GEM
|
||||||
json-schema (2.6.2)
|
json-schema (2.6.2)
|
||||||
addressable (~> 2.3.8)
|
addressable (~> 2.3.8)
|
||||||
jwt (1.5.6)
|
jwt (1.5.6)
|
||||||
kaminari (0.17.0)
|
kaminari (1.0.1)
|
||||||
actionpack (>= 3.0.0)
|
activesupport (>= 4.1.0)
|
||||||
activesupport (>= 3.0.0)
|
kaminari-actionview (= 1.0.1)
|
||||||
|
kaminari-activerecord (= 1.0.1)
|
||||||
|
kaminari-core (= 1.0.1)
|
||||||
|
kaminari-actionview (1.0.1)
|
||||||
|
actionview
|
||||||
|
kaminari-core (= 1.0.1)
|
||||||
|
kaminari-activerecord (1.0.1)
|
||||||
|
activerecord
|
||||||
|
kaminari-core (= 1.0.1)
|
||||||
|
kaminari-core (1.0.1)
|
||||||
kgio (2.10.0)
|
kgio (2.10.0)
|
||||||
knapsack (1.11.0)
|
knapsack (1.11.0)
|
||||||
rake
|
rake
|
||||||
|
@ -1011,7 +1020,7 @@ DEPENDENCIES
|
||||||
jquery-rails (~> 4.1.0)
|
jquery-rails (~> 4.1.0)
|
||||||
json-schema (~> 2.6.2)
|
json-schema (~> 2.6.2)
|
||||||
jwt (~> 1.5.6)
|
jwt (~> 1.5.6)
|
||||||
kaminari (~> 0.17.0)
|
kaminari (~> 1.0)
|
||||||
knapsack (~> 1.11.0)
|
knapsack (~> 1.11.0)
|
||||||
kubeclient (~> 2.2.0)
|
kubeclient (~> 2.2.0)
|
||||||
letter_opener_web (~> 1.3.0)
|
letter_opener_web (~> 1.3.0)
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Explore::ProjectsController < Explore::ApplicationController
|
||||||
def index
|
def index
|
||||||
params[:sort] ||= 'latest_activity_desc'
|
params[:sort] ||= 'latest_activity_desc'
|
||||||
@sort = params[:sort]
|
@sort = params[:sort]
|
||||||
@projects = load_projects.page(params[:page])
|
@projects = load_projects
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
|
@ -21,7 +21,7 @@ class Explore::ProjectsController < Explore::ApplicationController
|
||||||
def trending
|
def trending
|
||||||
params[:trending] = true
|
params[:trending] = true
|
||||||
@sort = params[:sort]
|
@sort = params[:sort]
|
||||||
@projects = load_projects.page(params[:page])
|
@projects = load_projects
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
|
@ -34,7 +34,7 @@ class Explore::ProjectsController < Explore::ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def starred
|
def starred
|
||||||
@projects = load_projects.reorder('star_count DESC').page(params[:page])
|
@projects = load_projects.reorder('star_count DESC')
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
|
@ -50,6 +50,9 @@ class Explore::ProjectsController < Explore::ApplicationController
|
||||||
|
|
||||||
def load_projects
|
def load_projects
|
||||||
ProjectsFinder.new(current_user: current_user, params: params)
|
ProjectsFinder.new(current_user: current_user, params: params)
|
||||||
.execute.includes(:route, namespace: :route)
|
.execute
|
||||||
|
.includes(:route, namespace: :route)
|
||||||
|
.page(params[:page])
|
||||||
|
.without_count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
module PaginationHelper
|
||||||
|
def paginate_collection(collection, remote: nil)
|
||||||
|
if collection.is_a?(Kaminari::PaginatableWithoutCount)
|
||||||
|
paginate_without_count(collection)
|
||||||
|
elsif collection.respond_to?(:total_pages)
|
||||||
|
paginate_with_count(collection, remote: remote)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def paginate_without_count(collection)
|
||||||
|
render(
|
||||||
|
'kaminari/gitlab/without_count',
|
||||||
|
previous_path: path_to_prev_page(collection),
|
||||||
|
next_path: path_to_next_page(collection)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def paginate_with_count(collection, remote: nil)
|
||||||
|
paginate(collection, remote: remote, theme: 'gitlab')
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
.gl-pagination
|
||||||
|
%ul.pagination.clearfix
|
||||||
|
- if previous_path
|
||||||
|
%li.prev
|
||||||
|
= link_to(t('views.pagination.previous'), previous_path, rel: 'prev')
|
||||||
|
- if next_path
|
||||||
|
%li.next
|
||||||
|
= link_to(t('views.pagination.next'), next_path, rel: 'next')
|
|
@ -23,6 +23,6 @@
|
||||||
= icon('lock fw', base: 'circle', class: 'fa-lg private-fork-icon')
|
= icon('lock fw', base: 'circle', class: 'fa-lg private-fork-icon')
|
||||||
%strong= pluralize(@private_forks_count, 'private fork')
|
%strong= pluralize(@private_forks_count, 'private fork')
|
||||||
%span you have no access to.
|
%span you have no access to.
|
||||||
= paginate(projects, remote: remote, theme: "gitlab") if projects.respond_to? :total_pages
|
= paginate_collection(projects, remote: remote)
|
||||||
- else
|
- else
|
||||||
.nothing-here-block No projects found
|
.nothing-here-block No projects found
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
title: Use Prev/Next pagination for exploring projects
|
||||||
|
merge_request:
|
||||||
|
author:
|
|
@ -0,0 +1,23 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe PaginationHelper do
|
||||||
|
describe '#paginate_collection' do
|
||||||
|
let(:collection) { User.all.page(1) }
|
||||||
|
|
||||||
|
it 'paginates a collection without using a COUNT' do
|
||||||
|
without_count = collection.without_count
|
||||||
|
|
||||||
|
expect(helper).to receive(:paginate_without_count)
|
||||||
|
.with(without_count)
|
||||||
|
.and_call_original
|
||||||
|
|
||||||
|
helper.paginate_collection(without_count)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'paginates a collection using a COUNT' do
|
||||||
|
expect(helper).to receive(:paginate_with_count).and_call_original
|
||||||
|
|
||||||
|
helper.paginate_collection(collection)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue