Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-12 09:19:20 +0300
committerStan Hu <stanhu@gmail.com>2018-07-12 11:00:15 +0300
commit081264f18682d7fa823f75737a919e05ea02fe04 (patch)
treea2f4e658e830e2bacfa6cbc6954a9f14e493dc34 /app/models/project_wiki.rb
parentba38931d90b6149e7bf1176dc5075b92a51466ae (diff)
Optimize ProjectWiki#empty? check
The `empty?` check was iterating over all Wiki pages to determine whether it was empty. Using the limit parameter allows us to bail out early once we found a page. Note that this currently only improves performance for GitLab 11.0 until https://gitlab.com/gitlab-org/gitaly/issues/1204 is fixed. Relates to #40101
Diffstat (limited to 'app/models/project_wiki.rb')
-rw-r--r--app/models/project_wiki.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb
index fc868c3ebb7..9ae2fb0013a 100644
--- a/app/models/project_wiki.rb
+++ b/app/models/project_wiki.rb
@@ -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)