Skip to content

Improve ordering of routes

Heinrich Lee Yu requested to merge improve-route-order into master

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:

  1. We load the path: /gitlab-org/gitlab/tracing
  2. 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'
  3. 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.
  4. It find the correct one for Projects::TracingsController#show with namespace_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

Availability and Testing

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
Edited by Heinrich Lee Yu

Merge request reports