forest_admin_rails 1.12.0 → 1.12.2

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: 12744bc9381af2c455a8ab1dd56e68443bc813d6f5df92f2b0f56a6fce4d3fa8
4
- data.tar.gz: d080d3ccbb57fecc113f6c0b41d871f115fc80e06dcb87a4fc6e0ee99fa1afc3
3
+ metadata.gz: 3f8e76e19bc58b11c12dd6d31f125fbe0543d6f33ff4463d9454e68ec43fdb4f
4
+ data.tar.gz: 130779408d7ecf0879ec80cc1cf1fef5be06b7f48848e7e0dcb9ca741ee43783
5
5
  SHA512:
6
- metadata.gz: 903af7b0abb45535e2e5e56bf358f8d3103f4518f48a0ff79b1bad9157bcd3ae19f5f323ff8a0530905deab1864f52034e2fc23403236fc612d4915e60328b13
7
- data.tar.gz: 34302839a5df138d04551410c2031764f1fee00be5fda460ae2a3d3cee9c089da6303e6cd5d220665175b405a17f5c3404d5317499607cbc9b0e94830007b94a
6
+ metadata.gz: 6116cedc55a13e68579903a099466eff89536c679f46c87dcbe787c74010ad3268983f5188d33adac1ebce34e4ad177cd0cd6195faa94e20e4aefef25dba18d3
7
+ data.tar.gz: 484024339f54c3a375ef3d65ac8d2ca9f5c1154be65491e0fa33eab698876d8e2319717bb1a3ece1850f6a2b5251524c77dd2ce340f0386b3495faf702529fe0
@@ -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
@@ -24,6 +24,10 @@ module ForestAdminRails
24
24
 
25
25
  extend ActiveSupport::Concern
26
26
 
27
+ initializer 'forest_admin_rails.add_autoload_paths', before: :set_autoload_paths do |app|
28
+ app.config.autoload_paths << Rails.root.join('lib')
29
+ end
30
+
27
31
  initializer 'forest_admin_rails.error_subscribe' do
28
32
  Rails.error.subscribe(ForestAdminErrorSubscriber.new)
29
33
  end
@@ -39,7 +43,28 @@ module ForestAdminRails
39
43
 
40
44
  def load_configuration
41
45
  return unless running_web_server?
42
- return unless File.exist?(Rails.root.join('app', 'lib', 'forest_admin_rails', 'create_agent.rb'))
46
+
47
+ old_path = Rails.root.join('app', 'lib', 'forest_admin_rails', 'create_agent.rb')
48
+ new_path = Rails.root.join('lib', 'forest_admin_rails', 'create_agent.rb')
49
+
50
+ # Check for old location and warn user
51
+ if File.exist?(old_path) && !File.exist?(new_path)
52
+ logger = ActiveSupport::Logger.new($stdout)
53
+ logger.warn <<~WARNING
54
+ ⚠️ DEPRECATION WARNING: create_agent.rb detected in old location!
55
+
56
+ The file 'app/lib/forest_admin_rails/create_agent.rb' should now be located at:
57
+ 'lib/forest_admin_rails/create_agent.rb'
58
+
59
+ Please move your file to the new location:
60
+ mkdir -p lib/forest_admin_rails
61
+ mv app/lib/forest_admin_rails/create_agent.rb lib/forest_admin_rails/create_agent.rb
62
+
63
+ This will become a hard requirement in a future version.
64
+ WARNING
65
+ end
66
+
67
+ return unless File.exist?(new_path) || File.exist?(old_path)
43
68
 
44
69
  # force eager loading models
45
70
  Rails.application.eager_load!
@@ -1,3 +1,3 @@
1
1
  module ForestAdminRails
2
- VERSION = "1.12.0"
2
+ VERSION = "1.12.2"
3
3
  end
@@ -8,7 +8,7 @@ module ForestAdminRails
8
8
  @auth_secret = SecureRandom.hex(20)
9
9
  @env_secret = env_secret
10
10
  template 'initializers/config.rb', 'config/initializers/forest_admin_rails.rb'
11
- template 'create_agent.rb', 'app/lib/forest_admin_rails/create_agent.rb'
11
+ template 'create_agent.rb', 'lib/forest_admin_rails/create_agent.rb'
12
12
  route 'mount ForestAdminRails::Engine => "#{ForestAdminRails.config[:prefix]}"'
13
13
  end
14
14
  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.12.0
4
+ version: 1.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu
@@ -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