Improve ordering of routes
What does this MR do?
First commit is extracted from !19412 (merged) which was merged but was reverted due to an edge case described in !19803 (comment 241805687)
This brings it back but keeps the existence check on ProjectUrlConstrainer
to handle the edge case.
This MR reorders route definitions so that more specific routes are prioritized over the more generic / catch-all routes. This makes Rails find the right route faster and reduces some unnecessary queries.
For example:
- We load the path:
/gitlab-org/gitlab/tracing
- Rails goes through the route definitions and finds the one for
ProjectsController#show
first. It matches this with:namespace_id: 'gitlab-org/gitlab', project_id: 'tracing'
-
ProjectUrlConstrainer
queries the DB and fails to find a project with that path and namespace so Rails moves on and tries to find another match. - It find the correct one for
Projects::TracingsController#show
withnamespace_id: 'gitlab-org', project_id: 'gitlab'
With this change, the router find the correct one first and we would avoid the query for the non-existent project.
This MR also moves all routes wrapped in Gitlab.ee
to the route file in ee/
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team