From 591c4aa1eae35136708849a4fd9574ed37d7744e Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Tue, 7 Nov 2023 20:07:23 -0800 Subject: [PATCH] Eager load Journey Formatter cache This cache is used when url_for is called without a named route (ie. when it's called with hash options). Eager loading avoids building the cache on the first call and potentially allows the memory to be shared via CoW on forking servers. --- actionpack/lib/action_dispatch/journey/formatter.rb | 5 +++++ actionpack/lib/action_dispatch/routing/route_set.rb | 1 + 2 files changed, 6 insertions(+) diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index bccedd4f6c837..b27f482f6cdf5 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -104,6 +104,11 @@ def clear @cache = nil end + def eager_load! + cache + nil + end + private def extract_parameterized_parts(route, options, recall) parameterized_parts = recall.merge(options) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 9d4adddb9e1eb..f5d665e7b72ee 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -386,6 +386,7 @@ def initialize(config = DEFAULT_CONFIG) def eager_load! router.eager_load! routes.each(&:eager_load!) + formatter.eager_load! nil end