summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2019-04-02 09:27:17 +0000
committerGitLab Release Tools Bot <robert+release-tools@gitlab.com>2019-04-02 15:26:54 +0000
commitbaef7edf8605eb67709f96e05d98ac33d5d03fe2 (patch)
tree5c110644fd73611bed2923a7e7e1e361c6860624
parentabab4322cbc50a9a2cadb9c8d0ebe999c794e48d (diff)
downloadgitlab-ce-baef7edf8605eb67709f96e05d98ac33d5d03fe2.tar.gz
Merge branch 'sh-fix-rugged-tree-entries' into 'master'
Avoid excessive recursive calls with Rugged TreeEntries Closes #59759 See merge request gitlab-org/gitlab-ce!26813 (cherry picked from commit d7583addf21cd4299363a5ce64126c37ca4234ea) 8686e012 Avoid excessive recursive calls with Rugged TreeEntries
-rw-r--r--changelogs/unreleased/sh-fix-rugged-tree-entries.yml5
-rw-r--r--lib/gitlab/git/rugged_impl/tree.rb20
-rw-r--r--spec/lib/gitlab/git/tree_spec.rb2
3 files changed, 18 insertions, 9 deletions
diff --git a/changelogs/unreleased/sh-fix-rugged-tree-entries.yml b/changelogs/unreleased/sh-fix-rugged-tree-entries.yml
new file mode 100644
index 00000000000..97b27678905
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-rugged-tree-entries.yml
@@ -0,0 +1,5 @@
+---
+title: Avoid excessive recursive calls with Rugged TreeEntries
+merge_request: 26813
+author:
+type: fixed
diff --git a/lib/gitlab/git/rugged_impl/tree.rb b/lib/gitlab/git/rugged_impl/tree.rb
index 0ebfd496695..bb13d114d46 100644
--- a/lib/gitlab/git/rugged_impl/tree.rb
+++ b/lib/gitlab/git/rugged_impl/tree.rb
@@ -15,12 +15,23 @@ module Gitlab
override :tree_entries
def tree_entries(repository, sha, path, recursive)
if Feature.enabled?(:rugged_tree_entries)
- tree_entries_from_rugged(repository, sha, path, recursive)
+ tree_entries_with_flat_path_from_rugged(repository, sha, path, recursive)
else
super
end
end
+ def tree_entries_with_flat_path_from_rugged(repository, sha, path, recursive)
+ tree_entries_from_rugged(repository, sha, path, recursive).tap do |entries|
+ # This was an optimization to reduce N+1 queries for Gitaly
+ # (https://gitlab.com/gitlab-org/gitaly/issues/530). It
+ # used to be done lazily in the view via
+ # TreeHelper#flatten_tree, so it's possible there's a
+ # performance impact by loading this eagerly.
+ rugged_populate_flat_path(repository, sha, path, entries)
+ end
+ end
+
def tree_entries_from_rugged(repository, sha, path, recursive)
current_path_entries = get_tree_entries_from_rugged(repository, sha, path)
ordered_entries = []
@@ -32,13 +43,6 @@ module Gitlab
ordered_entries.concat(tree_entries_from_rugged(repository, sha, entry.path, true))
end
end
-
- # This was an optimization to reduce N+1 queries for Gitaly
- # (https://gitlab.com/gitlab-org/gitaly/issues/530). It
- # used to be done lazily in the view via
- # TreeHelper#flatten_tree, so it's possible there's a
- # performance impact by loading this eagerly.
- rugged_populate_flat_path(repository, sha, path, ordered_entries)
end
def rugged_populate_flat_path(repository, sha, path, entries)
diff --git a/spec/lib/gitlab/git/tree_spec.rb b/spec/lib/gitlab/git/tree_spec.rb
index 60060c41616..7ad3cde97f8 100644
--- a/spec/lib/gitlab/git/tree_spec.rb
+++ b/spec/lib/gitlab/git/tree_spec.rb
@@ -19,7 +19,7 @@ describe Gitlab::Git::Tree, :seed_helper do
it 'returns a list of tree objects' do
entries = described_class.where(repository, SeedRepo::Commit::ID, 'files', true)
- expect(entries.count).to be > 10
+ expect(entries.count).to be >= 5
expect(entries).to all(be_a(Gitlab::Git::Tree))
end