summaryrefslogtreecommitdiff
path: root/app/models/repository.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-10-12 14:42:35 +0100
committerNick Thomas <nick@gitlab.com>2018-10-17 11:23:35 +0100
commit10a60f7d944f0bef0bdee92c3b0ad9c6137215d1 (patch)
treea229d3f74a75aa48f19a66bebb0bcaa555fb8d61 /app/models/repository.rb
parente347170cc59dfa1e48de451f7c48ccb65d3e581a (diff)
downloadgitlab-ce-10a60f7d944f0bef0bdee92c3b0ad9c6137215d1.tar.gz
Use cached readme blobs where appropriatenick.thomas/gitlab-ce-49591-use-cached-readme-blobs
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r--app/models/repository.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 6ce480c32c4..37a1dd64052 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -487,7 +487,20 @@ class Repository
end
def blob_at(sha, path)
- Blob.decorate(raw_repository.blob_at(sha, path), project)
+ blob = Blob.decorate(raw_repository.blob_at(sha, path), project)
+
+ # Don't attempt to return a special result if there is no blob at all
+ return unless blob
+
+ # Don't attempt to return a special result unless we're looking at HEAD
+ return blob unless head_commit&.sha == sha
+
+ case path
+ when head_tree&.readme_path
+ ReadmeBlob.new(blob, self)
+ else
+ blob
+ end
rescue Gitlab::Git::Repository::NoRepository
nil
end
@@ -569,9 +582,7 @@ class Repository
cache_method :merge_request_template_names, fallback: []
def readme
- if readme = tree(:head)&.readme
- ReadmeBlob.new(readme, self)
- end
+ head_tree&.readme
end
def rendered_readme