Improve `empty?` method in Wikis
Based on https://sentry.gitlab.net/gitlab/gitlabcom/issues/2478544/, when we are searching results from the wiki, we call method emtpy?
which calls wiki.list_pages
.
Method list_pages
calls wiki.list_pages
. When we call the internal wiki, we automatically create the wiki repository. This means that, every time we perform a search on wikis, we create the repository for these resources, which is not necessary.
We can improve the empty?
method by:
def empty?
!repository_exists? || list_pages(limit: 1).empty?
end
This way we can prevent creating the repository if it doesn't exist.
Edited by Francisco Javier López (ex-Gitlab)