diff options
author | Drew Blessing <drew@gitlab.com> | 2017-11-10 23:39:00 +0300 |
---|---|---|
committer | Drew Blessing <drew@gitlab.com> | 2017-11-15 17:28:33 +0300 |
commit | 03b1bcbb686f8e56fe6c6303adacdc01c5403790 (patch) | |
tree | 45e21665a23e6ce6ce616f91b1ea5901dcbccc48 /app/helpers | |
parent | a4072db0198896242886d22c644ed91c1016aa8d (diff) |
Truncate tree to max 1,000 items and display notice to users
Rendering ten thousands of tree items consumes a lot of server
time and can cause timeouts in extreme cases. Realistically,
displaying more than 1,000 files is probably not useful so
truncate and show the user a notice instead. 'Find files' can be
used to locate specific files beyond the 1,000 limit.
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/tree_helper.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index c4ea0f5ac53..0e106e2c85d 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -1,14 +1,23 @@ module TreeHelper + FILE_LIMIT = 1_000 + # Sorts a repository's tree so that folders are before files and renders # their corresponding partials # - # contents - A Grit::Tree object for the current tree + # tree - A `Tree` object for the current tree def render_tree(tree) # Sort submodules and folders together by name ahead of files folders, files, submodules = tree.trees, tree.blobs, tree.submodules - tree = "" + tree = '' items = (folders + submodules).sort_by(&:name) + files - tree << render(partial: "projects/tree/tree_row", collection: items) if items.present? + + if items.size > FILE_LIMIT + tree << render(partial: 'projects/tree/truncated_notice_tree_row', + locals: { limit: FILE_LIMIT, total: items.size }) + items = items.take(FILE_LIMIT) + end + + tree << render(partial: 'projects/tree/tree_row', collection: items) if items.present? tree.html_safe end |