Reduce number of gitaly calls in Snippet REST list Endpoints

In this commit, we're removing one Gitaly RPC call by storing
the content of that call and reusing it later.

Changelog: performance
parent e1cd303d
...@@ -5,16 +5,22 @@ module API ...@@ -5,16 +5,22 @@ module API
class Snippet < BasicSnippet class Snippet < BasicSnippet
expose :author, using: Entities::UserBasic expose :author, using: Entities::UserBasic
expose :file_name do |snippet| expose :file_name do |snippet|
snippet.file_name_on_repo || snippet.file_name snippet_files.first || snippet.file_name
end end
expose :files do |snippet, options| expose :files do |snippet, options|
snippet.list_files.map do |file| snippet_files.map do |file|
{ {
path: file, path: file,
raw_url: Gitlab::UrlBuilder.build(snippet, file: file, ref: snippet.repository.root_ref) raw_url: Gitlab::UrlBuilder.build(snippet, file: file, ref: snippet.repository.root_ref)
} }
end end
end end
private
def snippet_files
@snippet_files ||= object.list_files
end
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