routes_lazy_routes 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6e8fe43c0d0952ee2879a571fd73f2e01438f31c9000433c97d9263319eeac0
|
4
|
+
data.tar.gz: b685cac81ed7be0dccf6fb58a1a6e023a103b21839fecc906ec1745ab6602ad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f212b71f9b10cc35910813744f2053ebfadf88e090e964ecc124af5a2704aa52006d7d69ddf538757710c95878fa1527ee8886d9af8a039560a070f9fa268a86
|
7
|
+
data.tar.gz: 75e828ca879d28ff83f4ef41f4742ff196fc7dc14bec0ab5e8618240bef74ebb0c801b27a154a9b4f73f30dd7a58da4ef50ace22f9498eb5fb4ae223a9d902c8
|
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 you to wait dozens of seconds per every `rails` command invocation.
|
5
|
+
This voodoo gem is designed especially for you who are maintaining a huge legacy 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
|
@@ -30,7 +30,7 @@ You have nothing to do with it. It should just work beneath the skin.
|
|
30
30
|
|
31
31
|
## Trade-off
|
32
32
|
|
33
|
-
The first visitor of the server should sacrifice their time for the Rails process to load the routes.
|
33
|
+
The first visitor of the server should sacrifice their time for the Rails process to load the routes. First strike is deadly.
|
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
|
|
@@ -2,11 +2,24 @@
|
|
2
2
|
|
3
3
|
module RoutesLazyRoutes
|
4
4
|
module Application
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module LoadRunner
|
6
|
+
# We expect `Rails.application.eager_load!` to load all routes as well
|
7
|
+
def eager_load!
|
8
|
+
RoutesLazyRoutes.eager_load!
|
8
9
|
|
9
|
-
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module TaskLoader
|
15
|
+
# A monkey-patch that loads our Rake task for enhancing `rails routes` after Rails loads all other tasks.
|
16
|
+
# Just declaring our own `rake_tasks` in the railtie cannot achieve this, since calling each railtie's `rake_tasks` is done before requiring "rails/tasks",
|
17
|
+
# so enhancing Rails' Rake task from a gem this way seems impossible.
|
18
|
+
def load_tasks(*)
|
19
|
+
super
|
20
|
+
|
21
|
+
load "#{__dir__}/tasks/routes_lazy_routes.rake"
|
22
|
+
end
|
10
23
|
end
|
11
24
|
end
|
12
25
|
end
|
@@ -4,12 +4,15 @@ require_relative 'application'
|
|
4
4
|
|
5
5
|
module RoutesLazyRoutes
|
6
6
|
class Railtie < ::Rails::Railtie
|
7
|
-
|
7
|
+
# Extending `load_tasks` has to be done very early, like before executing any initializer, so here it is
|
8
|
+
Rails::Application.prepend RoutesLazyRoutes::Application::TaskLoader
|
9
|
+
|
10
|
+
initializer :routes_lazy_routes, before: :add_routing_paths do
|
8
11
|
RoutesLazyRoutes.arise!
|
9
12
|
|
10
13
|
Rails.application.config.middleware.use LazyRoutesMiddleware
|
11
14
|
|
12
|
-
Rails.application.extend RoutesLazyRoutes::Application
|
15
|
+
Rails.application.extend RoutesLazyRoutes::Application::LoadRunner
|
13
16
|
|
14
17
|
ActiveSupport.on_load :action_dispatch_integration_test, run_once: true do
|
15
18
|
RoutesLazyRoutes.eager_load!
|
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.3.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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/routes_lazy_routes/lazy_routes_middleware.rb
|
60
60
|
- lib/routes_lazy_routes/railtie.rb
|
61
61
|
- lib/routes_lazy_routes/routes_reloader_wrapper.rb
|
62
|
+
- lib/routes_lazy_routes/tasks/routes_lazy_routes.rake
|
62
63
|
- lib/routes_lazy_routes/version.rb
|
63
64
|
- routes_lazy_routes.gemspec
|
64
65
|
homepage: https://github.com/amatsuda/routes_lazy_routes
|