Merge branch 'sh-optimize-wiki-empty-check' into 'master'
Optimize ProjectWiki#empty? check See merge request gitlab-org/gitlab-ce!20573
This commit is contained in:
commit
6f8cf37ebe
3 changed files with 18 additions and 2 deletions
|
@ -20,7 +20,6 @@ class ProjectWiki
|
|||
@user = user
|
||||
end
|
||||
|
||||
delegate :empty?, to: :pages
|
||||
delegate :repository_storage, :hashed_storage?, to: :project
|
||||
|
||||
def path
|
||||
|
@ -74,6 +73,10 @@ class ProjectWiki
|
|||
!!find_page('home')
|
||||
end
|
||||
|
||||
def empty?
|
||||
pages(limit: 1).empty?
|
||||
end
|
||||
|
||||
# Returns an Array of Gitlab WikiPage instances or an
|
||||
# empty Array if this Wiki has no pages.
|
||||
def pages(limit: nil)
|
||||
|
|
5
changelogs/unreleased/sh-optimize-wiki-empty-check.yml
Normal file
5
changelogs/unreleased/sh-optimize-wiki-empty-check.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Optimize ProjectWiki#empty? check
|
||||
merge_request: 20573
|
||||
author:
|
||||
type: performance
|
|
@ -1,3 +1,4 @@
|
|||
# coding: utf-8
|
||||
require "spec_helper"
|
||||
|
||||
describe ProjectWiki do
|
||||
|
@ -10,7 +11,6 @@ describe ProjectWiki do
|
|||
|
||||
subject { project_wiki }
|
||||
|
||||
it { is_expected.to delegate_method(:empty?).to :pages }
|
||||
it { is_expected.to delegate_method(:repository_storage).to :project }
|
||||
it { is_expected.to delegate_method(:hashed_storage?).to :project }
|
||||
|
||||
|
@ -92,11 +92,19 @@ describe ProjectWiki do
|
|||
context "when the wiki has pages" do
|
||||
before do
|
||||
project_wiki.create_page("index", "This is an awesome new Gollum Wiki")
|
||||
project_wiki.create_page("another-page", "This is another page")
|
||||
end
|
||||
|
||||
describe '#empty?' do
|
||||
subject { super().empty? }
|
||||
it { is_expected.to be_falsey }
|
||||
|
||||
# Re-enable this when https://gitlab.com/gitlab-org/gitaly/issues/1204 is fixed
|
||||
xit 'only instantiates a Wiki page once' do
|
||||
expect(WikiPage).to receive(:new).once.and_call_original
|
||||
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue