Commit 60f68b71 authored by Mark Chao's avatar Mark Chao

Snippet explore to only show next/previous links

This avoids the costly total count query, needed to
compute links to the last page.
parent 272d02bf
# frozen_string_literal: true # frozen_string_literal: true
class Explore::SnippetsController < Explore::ApplicationController class Explore::SnippetsController < Explore::ApplicationController
include PaginatedCollection
include Gitlab::NoteableMetadata include Gitlab::NoteableMetadata
def index def index
@snippets = SnippetsFinder.new(current_user, explore: true) @snippets = SnippetsFinder.new(current_user, explore: true)
.execute .execute
.page(params[:page]) .page(params[:page])
.without_count
.inc_author .inc_author
return if redirect_out_of_range(@snippets)
@noteable_meta_data = noteable_meta_data(@snippets, 'Snippet') @noteable_meta_data = noteable_meta_data(@snippets, 'Snippet')
end end
end end
...@@ -8,4 +8,4 @@ ...@@ -8,4 +8,4 @@
%ul.content-list %ul.content-list
= render partial: 'shared/snippets/snippet', collection: @snippets, locals: { link_project: link_project } = render partial: 'shared/snippets/snippet', collection: @snippets, locals: { link_project: link_project }
= paginate @snippets, theme: 'gitlab', remote: remote = paginate_collection @snippets, remote: remote
---
title: Showing only "Next" button for snippet explore page.
merge_request: 25404
author:
type: changed
...@@ -4,12 +4,33 @@ require 'spec_helper' ...@@ -4,12 +4,33 @@ require 'spec_helper'
describe Explore::SnippetsController do describe Explore::SnippetsController do
describe 'GET #index' do describe 'GET #index' do
it_behaves_like 'paginated collection' do let!(:project_snippet) { create_list(:project_snippet, 3, :public) }
let(:collection) { Snippet.all } let!(:personal_snippet) { create_list(:personal_snippet, 3, :public) }
before do before do
create(:personal_snippet, :public) allow(Kaminari.config).to receive(:default_per_page).and_return(2)
end end
it 'renders' do
get :index
snippets = assigns(:snippets)
expect(snippets).to be_a(::Kaminari::PaginatableWithoutCount)
expect(snippets.size).to eq(2)
expect(snippets).to all(be_a(PersonalSnippet))
expect(response).to have_gitlab_http_status(:ok)
end
it 'renders pagination' do
get :index, params: { page: 2 }
snippets = assigns(:snippets)
expect(snippets).to be_a(::Kaminari::PaginatableWithoutCount)
expect(snippets.size).to eq(1)
expect(assigns(:snippets)).to all(be_a(PersonalSnippet))
expect(response).to have_gitlab_http_status(:ok)
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment