Skip to content

WIP Simplify project routing regex

Dmytro Zaporozhets (DZ) requested to merge dz-simplify-routes-regex into master

What does this MR do?

This MR is attempt to improve routing performance by simplifying regex we use for project routes. In particular namespace_id is the one affected. We do so by creating a set of regex used for routing but without reserved words in it.

Before

→ be rake routes | grep transfer_namespace_project
                                      
transfer_namespace_project PUT                   /*namespace_id/:id/transfer(.:format)                                                                              projects#transfer {
  :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|login|oauth|profile|projects|public|robots\.txt|s|search|sent_notifications|slash\-command\-logo\.png|snippets|unsubscribes|uploads|users|v2))\/)(?-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))))*/}

After

→ be rake routes | grep transfer_namespace_project
                                      
transfer_namespace_project PUT                   /*namespace_id/:id/transfer(.:format)                                                                              projects#transfer {
  :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:\-))\/)(?-mix:(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])(?-mix:(?<!\.git|\.atom))))(?:\/(?!(?i-mx:\-)\/)(?-mix:(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])(?-mix:(?<!\.git|\.atom))))*/}

Downsides

We have quite a restrictive regex on namespace_id. There might be bugs with routing that we did not see because of it.

Does this MR meet the acceptance criteria?

Conformity

Edited by Dmytro Zaporozhets (DZ)

Merge request reports