1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Reduce loops in head route matching

This commit is contained in:
Vinicius Stock 2020-04-09 16:17:18 -04:00
parent 8544c9c236
commit d7ac60719a
No known key found for this signature in database
GPG key ID: 1A3EC85374C0969A

View file

@ -110,11 +110,10 @@ module ActionDispatch
r.path.match?(req.path_info)
}
routes =
if req.head?
match_head_routes(routes, req)
routes = match_head_routes(routes, req)
else
match_routes(routes, req)
routes.select! { |r| r.matches?(req) }
end
routes.sort_by!(&:precedence)
@ -131,23 +130,16 @@ module ActionDispatch
end
def match_head_routes(routes, req)
verb_specific_routes = routes.select(&:requires_matching_verb?)
head_routes = match_routes(verb_specific_routes, req)
head_routes = routes.select { |r| r.requires_matching_verb? && r.matches?(req) }
return head_routes unless head_routes.empty?
if head_routes.empty?
begin
req.request_method = "GET"
match_routes(routes, req)
routes.select! { |r| r.matches?(req) }
routes
ensure
req.request_method = "HEAD"
end
else
head_routes
end
end
def match_routes(routes, req)
routes.select { |r| r.matches?(req) }
end
end
end