Skip to content

Fix lookup of namespace by pages host

Krasimir Angelov requested to merge fix-namespace-lookup-by-pages-host into master

What does this MR do?

With !25585 (merged) we tried to optimize lookup for namespace domains by using Namespace.find_by_path instead of Namespace.find_by_full_path with the assumption we only deal with top level domains for Pages subdomains.

Unfortunately if you have subgroup with same path as top level group it may be picked up instead - if we look for bar.gitlab.io we'll query for path='bar' and it can return subgroup foo/bar.

This MR updates find_by_full_path to where("parent_id is null").find_by_path(name)to ensure we returnonly top-level domains. Alternatively we can go back tofind_by_full_pathbut there really no need to join withroutes`.

Execution plan for the query before - https://explain.depesz.com/s/VECi.

Execution plan for the query after - https://explain.depesz.com/s/KxUW.

I think at this point we do not need specialized index on (path) WHERE parent_id IS NULL but will keep an eye to the endpoint once we rollback the Pages API again.

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 Grzegorz Bizon

Merge request reports