routes_lazy_routes 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +12 -1
- data/lib/routes_lazy_routes.rb +7 -0
- data/lib/routes_lazy_routes/application.rb +12 -0
- data/lib/routes_lazy_routes/lazy_routes_middleware.rb +3 -8
- data/lib/routes_lazy_routes/railtie.rb +10 -0
- data/lib/routes_lazy_routes/routes_reloader_wrapper.rb +10 -2
- data/lib/routes_lazy_routes/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d328eaa59962f83c7d301afe8040f66b51b2c524fd59cde08ee68f49e5d2a478
|
4
|
+
data.tar.gz: 16c074d69396f4205076238e56b4e7e1f6fedb38eff428d52454fe24173b2634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8869ac12f5faa11b76cdb5301c56dd88a1ec0904eb2edab3888e9ac47724bbe72bf85667aba7665f5262b34fca13ef5c04350f0b5ecea4da8cb632618bf8150
|
7
|
+
data.tar.gz: c81344fc4c6f912554d5ea2aa5210690ba31dbbac0070584e7a50fc343bb3df6455f8847449fcd381f68c6084fd7db2e1ada4c4eb325c2d63fe3c07246892005
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
routes_lazy_routes is an evil Rails plugin that defers loading the whole bloody routes until the server gets the first request, so the app can spin up quickly. 🤘
|
4
4
|
|
5
|
-
This voodoo gem is designed especially for you who are maintaining a Rails app that contains hundreds of routes that forces to wait dozens of seconds per every `rails` command invocation.
|
5
|
+
This voodoo gem is designed especially for you who are maintaining a Rails app that contains hundreds of routes that forces you to wait dozens of seconds per every `rails` command invocation.
|
6
6
|
|
7
7
|
|
8
8
|
## Installation
|
@@ -34,6 +34,17 @@ The first visitor of the server should sacrifice their time for the Rails proces
|
|
34
34
|
If you're bundling this in the production server, it'd be a good idea to throw a jab to the server right after the deployment in order to warm up before accepting real client requests.
|
35
35
|
|
36
36
|
|
37
|
+
## Notes
|
38
|
+
|
39
|
+
- You can manually eager_load the routes by calling `RoutesLazyRoutes.eager_load!` (the "load runner").
|
40
|
+
|
41
|
+
- `Rails.application.eager_load!` automatically invokes `RoutesLazyRoutes.eager_load!` since that should be what we expect for `Rails.application.eager_load!`.
|
42
|
+
|
43
|
+
- Loading an integration test automatically kicks `RoutesLazyRoutes.eager_load!` since AD::Integration expects the routes to be loaded.
|
44
|
+
|
45
|
+
- And, as already explained, sending a request to the Rails server automatically runs `RoutesLazyRoutes.eager_load!` on the server.
|
46
|
+
|
47
|
+
|
37
48
|
## Contributing
|
38
49
|
|
39
50
|
Patches are welcome on GitHub at https://github.com/amatsuda/routes_lazy_routes.
|
data/lib/routes_lazy_routes.rb
CHANGED
@@ -2,20 +2,15 @@
|
|
2
2
|
|
3
3
|
module RoutesLazyRoutes
|
4
4
|
class LazyRoutesMiddleware
|
5
|
-
def initialize(app
|
5
|
+
def initialize(app)
|
6
6
|
@app = app
|
7
|
-
@original_routes_reloader = original_routes_reloader
|
8
|
-
@mutex = Mutex.new
|
9
7
|
@loaded = false
|
10
8
|
end
|
11
9
|
|
12
10
|
def call(env)
|
13
11
|
unless @loaded
|
14
|
-
|
15
|
-
|
16
|
-
@original_routes_reloader.execute
|
17
|
-
@loaded = true
|
18
|
-
end
|
12
|
+
RoutesLazyRoutes.eager_load!
|
13
|
+
@loaded = true
|
19
14
|
end
|
20
15
|
|
21
16
|
@app.call env
|
@@ -1,9 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'application'
|
4
|
+
|
3
5
|
module RoutesLazyRoutes
|
4
6
|
class Railtie < ::Rails::Railtie
|
5
7
|
initializer 'routes_lazy_routes', before: :add_routing_paths do
|
6
8
|
RoutesLazyRoutes.arise!
|
9
|
+
|
10
|
+
Rails.application.config.middleware.use LazyRoutesMiddleware
|
11
|
+
|
12
|
+
Rails.application.extend RoutesLazyRoutes::Application
|
13
|
+
|
14
|
+
ActiveSupport.on_load :action_dispatch_integration_test, run_once: true do
|
15
|
+
RoutesLazyRoutes.eager_load!
|
16
|
+
end
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
@@ -6,12 +6,20 @@ module RoutesLazyRoutes
|
|
6
6
|
|
7
7
|
def initialize(original_routes_reloader)
|
8
8
|
@original_routes_reloader = original_routes_reloader
|
9
|
-
|
10
|
-
Rails.application.config.middleware.use LazyRoutesMiddleware, original_routes_reloader
|
9
|
+
@mutex = Mutex.new
|
11
10
|
end
|
12
11
|
|
13
12
|
def execute
|
14
13
|
# pretty vacant
|
15
14
|
end
|
15
|
+
|
16
|
+
def reload!
|
17
|
+
@mutex.synchronize do
|
18
|
+
if Rails.application.routes_reloader == self
|
19
|
+
Rails.application.instance_variable_set :@routes_reloader, @original_routes_reloader
|
20
|
+
@original_routes_reloader.execute
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: routes_lazy_routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- bin/console
|
56
56
|
- bin/setup
|
57
57
|
- lib/routes_lazy_routes.rb
|
58
|
+
- lib/routes_lazy_routes/application.rb
|
58
59
|
- lib/routes_lazy_routes/lazy_routes_middleware.rb
|
59
60
|
- lib/routes_lazy_routes/railtie.rb
|
60
61
|
- lib/routes_lazy_routes/routes_reloader_wrapper.rb
|