Commit dbf924c5 authored by Michael Kozono's avatar Michael Kozono

Simplify query

Performance does not need to be optimized in this case because this will be run in batches at a controlled rate.
parent f1e963bd
...@@ -28,25 +28,14 @@ module Gitlab ...@@ -28,25 +28,14 @@ module Gitlab
<<~ROUTES_MATCH_REDIRECTS <<~ROUTES_MATCH_REDIRECTS
EXISTS ( EXISTS (
SELECT 1 FROM routes SELECT 1 FROM routes
WHERE (#{route_paths_match_redirects}) WHERE (
LOWER(redirect_routes.path) = LOWER(routes.path)
OR LOWER(redirect_routes.path) LIKE LOWER(CONCAT(routes.path, '/%'))
)
AND routes.id BETWEEN #{start_id} AND #{end_id} AND routes.id BETWEEN #{start_id} AND #{end_id}
) )
ROUTES_MATCH_REDIRECTS ROUTES_MATCH_REDIRECTS
end end
def route_paths_match_redirects
if Gitlab::Database.postgresql?
<<~ROUTE_PATHS_MATCH_REDIRECTS
LOWER(redirect_routes.path) = LOWER(routes.path)
OR LOWER(redirect_routes.path) LIKE LOWER(CONCAT(routes.path, '/%'))
ROUTE_PATHS_MATCH_REDIRECTS
else
<<~ROUTE_PATHS_MATCH_REDIRECTS
redirect_routes.path = routes.path
OR redirect_routes.path LIKE CONCAT(routes.path, '/%')
ROUTE_PATHS_MATCH_REDIRECTS
end
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment