routes_lazy_routes 0.2.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +17 -2
- data/Gemfile +2 -0
- data/README.md +2 -2
- data/lib/routes_lazy_routes/application.rb +17 -4
- data/lib/routes_lazy_routes/command/routes_command.rb +14 -0
- data/lib/routes_lazy_routes/railtie.rb +10 -2
- data/lib/routes_lazy_routes/routes_reloader_wrapper.rb +1 -1
- data/lib/routes_lazy_routes/tasks/routes_lazy_routes.rake +11 -0
- data/lib/routes_lazy_routes/version.rb +1 -1
- data/routes_lazy_routes.gemspec +2 -1
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3a53d214d3a09b1d78449db704c5c01f161848c502e5db060d49445a27cbc44
|
4
|
+
data.tar.gz: 3a1f0142211703faa3e74d038500376f38886bc44c904e55796a456bbdcb5cbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d808c84a2d36a0ba6f0ae2bf292a157ae3912a052ccf4f8b6a557e7156591b58ddf1121dc73bcf9db32a8a363c69cf8d3ca71331acddbabc3b960785211db62
|
7
|
+
data.tar.gz: 2a9219db0ec56fa7a120d736824ddf63f53af888f1f0cbb959c80857d07f79a1d015dcef2de3f29fd9aedaaa42ce81662541f433acb7d4cf6869c514df421970
|
data/.github/workflows/main.yml
CHANGED
@@ -4,15 +4,30 @@ on: [push,pull_request]
|
|
4
4
|
|
5
5
|
jobs:
|
6
6
|
build:
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
include:
|
10
|
+
- ruby-version: 2.7.3
|
11
|
+
rails-version: '~> 5.2.4'
|
12
|
+
- ruby-version: 2.7.3
|
13
|
+
rails-version: '~> 6.0.3'
|
14
|
+
- ruby-version: 2.7.3
|
15
|
+
rails-version: '~> 6.1.0'
|
16
|
+
- ruby-version: 3.0.1
|
17
|
+
rails-version: '~> 6.0.3'
|
18
|
+
- ruby-version: 3.0.1
|
19
|
+
rails-version: '~> 6.1.0'
|
7
20
|
runs-on: ubuntu-latest
|
8
21
|
steps:
|
9
22
|
- uses: actions/checkout@v2
|
10
23
|
- name: Set up Ruby
|
11
24
|
uses: ruby/setup-ruby@v1
|
12
25
|
with:
|
13
|
-
ruby-version:
|
26
|
+
ruby-version: ${{ matrix.ruby-version }}
|
14
27
|
- name: Run the default task
|
15
28
|
run: |
|
16
|
-
gem install bundler
|
29
|
+
gem install bundler
|
17
30
|
bundle install
|
18
31
|
bundle exec rake
|
32
|
+
env:
|
33
|
+
RAILS_VERSION: ${{ matrix.rails-version }}
|
data/Gemfile
CHANGED
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 `rake 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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RoutesLazyRoutes
|
4
|
+
module Command
|
5
|
+
module RoutesCommand
|
6
|
+
# A monkey-patch that eager_loads the routes right before running the `rails routes` command.
|
7
|
+
def require_environment!
|
8
|
+
super
|
9
|
+
|
10
|
+
RoutesLazyRoutes.eager_load!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -4,12 +4,20 @@ require_relative 'application'
|
|
4
4
|
|
5
5
|
module RoutesLazyRoutes
|
6
6
|
class Railtie < ::Rails::Railtie
|
7
|
-
|
7
|
+
# Extending the following modules have to be done very early, like before executing any initializer, so here it is
|
8
|
+
Rails::Application.prepend RoutesLazyRoutes::Application::TaskLoader
|
9
|
+
|
10
|
+
if defined? Rails::Command::RoutesCommand
|
11
|
+
require_relative 'command/routes_command'
|
12
|
+
Rails::Command::RoutesCommand.prepend RoutesLazyRoutes::Command::RoutesCommand
|
13
|
+
end
|
14
|
+
|
15
|
+
initializer :routes_lazy_routes, before: :add_routing_paths do
|
8
16
|
RoutesLazyRoutes.arise!
|
9
17
|
|
10
18
|
Rails.application.config.middleware.use LazyRoutesMiddleware
|
11
19
|
|
12
|
-
Rails.application.extend RoutesLazyRoutes::Application
|
20
|
+
Rails.application.extend RoutesLazyRoutes::Application::LoadRunner
|
13
21
|
|
14
22
|
ActiveSupport.on_load :action_dispatch_integration_test, run_once: true do
|
15
23
|
RoutesLazyRoutes.eager_load!
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RoutesLazyRoutes
|
4
4
|
class RoutesReloaderWrapper
|
5
|
-
delegate :paths, :eager_load=, :updated?, :route_sets, to: :@original_routes_reloader
|
5
|
+
delegate :paths, :eager_load=, :updated?, :route_sets, :external_routes, to: :@original_routes_reloader
|
6
6
|
|
7
7
|
def initialize(original_routes_reloader)
|
8
8
|
@original_routes_reloader = original_routes_reloader
|
data/routes_lazy_routes.gemspec
CHANGED
metadata
CHANGED
@@ -1,17 +1,31 @@
|
|
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.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionpack
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
@@ -56,9 +70,11 @@ files:
|
|
56
70
|
- bin/setup
|
57
71
|
- lib/routes_lazy_routes.rb
|
58
72
|
- lib/routes_lazy_routes/application.rb
|
73
|
+
- lib/routes_lazy_routes/command/routes_command.rb
|
59
74
|
- lib/routes_lazy_routes/lazy_routes_middleware.rb
|
60
75
|
- lib/routes_lazy_routes/railtie.rb
|
61
76
|
- lib/routes_lazy_routes/routes_reloader_wrapper.rb
|
77
|
+
- lib/routes_lazy_routes/tasks/routes_lazy_routes.rake
|
62
78
|
- lib/routes_lazy_routes/version.rb
|
63
79
|
- routes_lazy_routes.gemspec
|
64
80
|
homepage: https://github.com/amatsuda/routes_lazy_routes
|
@@ -82,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
98
|
- !ruby/object:Gem::Version
|
83
99
|
version: '0'
|
84
100
|
requirements: []
|
85
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.3.0.dev
|
86
102
|
signing_key:
|
87
103
|
specification_version: 4
|
88
104
|
summary: A Rails routes lazy loader
|