Reduce TOP_LEVEL_ROUTES and ban future expansion
As mentioned in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/27518#note_171721446, I'd like to propose that we somehow find ways to reduce the number of entries in lib/path_regex.rb
in TOP_LEVEL_ROUTES
and ban future additions. If you run bundle exec rake routes
, you'll see that every endpoint now has a massive regular expression like so:
projects#destroy {:id=>/(?!((?i-mx:\-|badges|blame|blob|builds|commits|create|create_dir|edit|environments\/folders|files|find_file|gitlab\-lfs\/objects|info\/lfs\/objects|new|preview|raw|refs|tree|update|wikis))\/)(?-mix:(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*)(?-mix:(?<!\.git|\.atom)))/, :namespace_id=>/(?-mix:(?!((?i-mx:\-|\.well\-known|404\.html|422\.html|500\.html|502\.html|503\.html|abuse_reports|admin|api|apple\-touch\-icon\-precomposed\.png|apple\-touch\-icon\.png|assets|autocomplete|ci|dashboard|deploy\.html|explore|favicon\.ico|favicon\.png|files|groups|health_check|help|import|invites|jwt|koding|login|notification_settings|oauth|profile|projects|public|robots\.txt|s|search|sent_notifications|slash\-command\-logo\.png|snippets|u|unsubscribes|uploads|users))\/)(?-mix:(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])(?-mix:(?<!\.git|\.atom))))(?:\/(?!(?i-mx:\-|badges|blame|blob|builds|commits|create|create_dir|edit|environments\/folders|files|find_file|gitlab\-lfs\/objects|info\/lfs\/objects|new|preview|raw|refs|tree|update|wikis)\/)(?-mix:(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])(?-mix:(?<!\.git|\.atom))))*/}
Every time a Rails controller has to match an endpoint, it has to do this giant regex comparison. I've seen this show up in our performance traces, somewhere.
It seems to me that we should be moving endpoints into the /-/
namespace where possible?
What do you think @gitlab-org/maintainers/rails-backend?