diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2019-07-13 09:01:53 +0300 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2019-07-16 13:45:11 +0300 |
commit | 2b5ec95feba38b39689e8ae4ad60a3bcefa557a2 (patch) | |
tree | cdc325cc960ec2cb94d7ac27fe16fbfcda25dffc /lib | |
parent | fadf4f1a7ce936e47f82eecaa5575fac1ecc5130 (diff) | |
download | gitlab-ce-2b5ec95feba38b39689e8ae4ad60a3bcefa557a2.tar.gz |
Make 1 Gitaly request to get submodule urls
Now 1 request is performed instead of 2 per submodule
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 21 | ||||
-rw-r--r-- | lib/gitlab/graphql/representation/submodule_tree_entry.rb | 41 |
2 files changed, 59 insertions, 3 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index b7b7578cef9..87284776db0 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -464,6 +464,18 @@ module Gitlab end end + # Returns path to url mappings for submodules + # + # Ex. + # @repository.submodule_urls_for('master') + # # => { 'rack' => 'git@localhost:rack.git' } + # + def submodule_urls_for(ref) + wrapped_gitaly_errors do + gitaly_submodule_urls_for(ref) + end + end + # Return total commits count accessible from passed ref def commit_count(ref) wrapped_gitaly_errors do @@ -1059,12 +1071,15 @@ module Gitlab return unless commit_object && commit_object.type == :COMMIT + gitaly_submodule_urls_for(ref)[path] + end + + def gitaly_submodule_urls_for(ref) gitmodules = gitaly_commit_client.tree_entry(ref, '.gitmodules', Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) return unless gitmodules - found_module = GitmodulesParser.new(gitmodules.data).parse[path] - - found_module && found_module['url'] + submodules = GitmodulesParser.new(gitmodules.data).parse + submodules.transform_values { |submodule| submodule['url'] } end # Returns true if the given ref name exists diff --git a/lib/gitlab/graphql/representation/submodule_tree_entry.rb b/lib/gitlab/graphql/representation/submodule_tree_entry.rb new file mode 100644 index 00000000000..80d254ce68a --- /dev/null +++ b/lib/gitlab/graphql/representation/submodule_tree_entry.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Gitlab + module Graphql + module Representation + class SubmoduleTreeEntry < SimpleDelegator + class << self + def decorate(tree) + repository = tree.repository + submodule_urls = repository.submodule_urls_for(tree.sha) + + tree.submodules.map do |submodule| + self.new(submodule, submodule_urls[submodule.path], repository) + end + end + end + + def initialize(submodule, submodule_url, repository) + @submodule_url = submodule_url + @repository = repository + + super(submodule) + end + + def web_url + submodule_links.first + end + + def tree_url + submodule_links.last + end + + private + + def submodule_links + @links ||= SubmoduleHelper.submodule_links_for_url(id, @submodule_url, @repository) + end + end + end + end +end |