forest_admin_rails 1.11.4 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72d672e618107231916cb1e5c56dc411812d4ebd6cccefa8a293cf38e2a27b51
4
- data.tar.gz: 5f121f35d527fbbbaa105c927601a8c1d1f14ea40d7c769b0a90d93489be7e28
3
+ metadata.gz: '099b5f8e72f047e94d152def7e081f05321c7bf0b1aaa75f0484c917acd7fc61'
4
+ data.tar.gz: 0af28ac77c06cbed7cb5212c244232a1f3a3e42aa64a49f02c34281f821d61a9
5
5
  SHA512:
6
- metadata.gz: 899af932e59899b79a1faab16b5f00bcd9dab091a04c44657f64d5a7b4008a3add6aba522b1bf6dedf2eba1511d195c965542e44722cda5c137cbabde4cae466
7
- data.tar.gz: cedfede0e08881a8faf852e1156cb986051b403b0f2656b9c2621b62fcdd02fcb93df7a2f33f20286c2f37e50aa86c608d327eb5f6b71dcbef25f61006bee96c
6
+ metadata.gz: c1c0422ec8739e19267569261e0afe16e1cca5f1673cbf65ceab6142000c9df32b96235745fad440b16e67d4f9751a1b1785ed6b15fde86f404f4e62dd09c973
7
+ data.tar.gz: ab902ad4d0e18a6f5dd332f9e358f7d018208f7c931984f86b7ebeafe0b3717c23058f2a723adfbe32ccfc599df483d3bb67ab54535e17b1d0720489f9eed043
@@ -7,8 +7,8 @@ module ForestAdminRails
7
7
  skip_forgery_protection
8
8
 
9
9
  def index
10
- if ForestAdminAgent::Http::Router.routes.key? params['route_alias']
11
- route = ForestAdminAgent::Http::Router.routes[params['route_alias']]
10
+ if ForestAdminAgent::Http::Router.cached_routes.key? params['route_alias']
11
+ route = ForestAdminAgent::Http::Router.cached_routes[params['route_alias']]
12
12
 
13
13
  begin
14
14
  forest_response route[:closure].call({ params: params.to_unsafe_h, headers: request.headers.to_h })
@@ -0,0 +1,29 @@
1
+ if defined?(ForestAdminAgent::Http::Router)
2
+ cache_disabled = ForestAdminAgent::Http::Router.cache_disabled?
3
+
4
+ if cache_disabled
5
+ Rails.logger.warn('[ForestAdmin] Route caching is DISABLED - this will impact performance')
6
+ Rails.logger.warn('[ForestAdmin] To enable caching, remove disable_route_cache: true from configuration')
7
+ else
8
+ Rails.application.config.after_initialize do
9
+ start_time = Time.now
10
+ routes = ForestAdminAgent::Http::Router.cached_routes
11
+ elapsed = ((Time.now - start_time) * 1000).round(2)
12
+
13
+ Rails.logger.info(
14
+ "[ForestAdmin] Successfully pre-cached #{routes.size} routes in #{elapsed}ms"
15
+ )
16
+ rescue StandardError => e
17
+ Rails.logger.error(
18
+ "[ForestAdmin] CRITICAL: Failed to pre-cache routes: #{e.class} - #{e.message}"
19
+ )
20
+ Rails.logger.error(e.backtrace.first(10).join("\n"))
21
+
22
+ raise e if Rails.env.production?
23
+
24
+ Rails.logger.warn(
25
+ '[ForestAdmin] Routes will be computed on first request (performance degradation)'
26
+ )
27
+ end
28
+ end
29
+ end
data/config/routes.rb CHANGED
@@ -1,15 +1,20 @@
1
1
  ForestAdminRails::Engine.routes.draw do
2
- Rails.error.handle(ForestAdminDatasourceToolkit::Exceptions::ForestException) do
3
- scope '/forest' do
4
- ForestAdminAgent::Http::Router.routes.each do |name, agent_route|
5
- match agent_route[:uri],
6
- defaults: { format: agent_route[:format] },
7
- to: 'forest#index',
8
- via: agent_route[:method],
9
- as: name,
10
- route_alias: name,
11
- constraints: { id: /[a-zA-Z0-9\.]*+/ }
12
- end
2
+ scope '/forest' do
3
+ # Use cached_routes to avoid recomputing routes during Rails route initialization
4
+ ForestAdminAgent::Http::Router.cached_routes.each do |name, agent_route|
5
+ match agent_route[:uri],
6
+ defaults: { format: agent_route[:format] },
7
+ to: 'forest#index',
8
+ via: agent_route[:method],
9
+ as: name,
10
+ route_alias: name,
11
+ constraints: { id: /[a-zA-Z0-9\.]*+/ }
13
12
  end
13
+ rescue StandardError => e
14
+ if defined?(Rails) && Rails.logger
15
+ Rails.logger.error("[ForestAdmin] CRITICAL: Failed to initialize routes: #{e.class} - #{e.message}")
16
+ Rails.logger.error(e.backtrace.join("\n"))
17
+ end
18
+ raise e
14
19
  end
15
20
  end
@@ -70,6 +70,8 @@ module ForestAdminRails
70
70
  end
71
71
 
72
72
  def load_cors
73
+ return if ENV['FOREST_CORS_DEACTIVATED']
74
+
73
75
  config.middleware.insert_before 0, Rack::Cors do
74
76
  allow do
75
77
  hostnames = [/\A.*\.forestadmin\.com\z/]
@@ -1,3 +1,3 @@
1
1
  module ForestAdminRails
2
- VERSION = "1.11.4"
2
+ VERSION = "1.12.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_admin_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.4
4
+ version: 1.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-10-22 00:00:00.000000000 Z
12
+ date: 2025-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-configurable
@@ -68,6 +68,7 @@ files:
68
68
  - app/controllers/forest_admin_rails/forest_controller.rb
69
69
  - app/helpers/forest_admin_rails/application_helper.rb
70
70
  - config/initializers/forest_admin_error_subscriber.rb
71
+ - config/initializers/forest_admin_route_cache.rb
71
72
  - config/routes.rb
72
73
  - lib/forest_admin_rails.rb
73
74
  - lib/forest_admin_rails/engine.rb