Addressable::URI interprets the `#` in a URI as a URI fragment
and does not escape it, but Rails has special helpers that treats
these as bona-fide characters that need to be escaped.
Closes https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/23368
Rails is slow to generate paths dynamically especially when called
hundreds/thousands of times. Also, rendering many partials hundreds
of times can be slower. This change reduces the number of partials
rendered and introduces two fast path methods to speed up path
generation.
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.