routes_lazy_routes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +11 -0
- data/Gemfile +10 -0
- data/MIT-LICENSE +21 -0
- data/README.md +44 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/routes_lazy_routes.rb +21 -0
- data/lib/routes_lazy_routes/lazy_routes_middleware.rb +24 -0
- data/lib/routes_lazy_routes/railtie.rb +9 -0
- data/lib/routes_lazy_routes/routes_reloader_wrapper.rb +17 -0
- data/lib/routes_lazy_routes/version.rb +5 -0
- data/routes_lazy_routes.gemspec +30 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 776e64fd7ac17ff3e62acfb3cafd7e908ed32de16d798ecda0f9e494abdca344
|
4
|
+
data.tar.gz: 5c8811a1b1411849d27e2988f9a4d12db36a9fbbfd5c6676d383903678c85f44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 444b44d3d13ba5eff7a1c1b2960eba368295223506e460b48156eb7a5046e94a208adefabc855d48f560de5cef5151b0ea6d58fa027378b3ba9096a6bcaf5c12
|
7
|
+
data.tar.gz: a3ae5366ea23776ac6aeabfcaf7b3116adfb47aa7c7ec2becf97a22b62ed856001fee1d2d2d1d8dcb591f584b4aa6553d641da1ecd7f0fdb5887dd27d4bccf9b
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.0
|
14
|
+
- name: Run the default task
|
15
|
+
run: |
|
16
|
+
gem install bundler -v 2.2.0.rc.2
|
17
|
+
bundle install
|
18
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Akira Matsuda
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# routes_lazy_routes
|
2
|
+
|
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
|
+
|
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.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'routes_lazy_routes'
|
14
|
+
```
|
15
|
+
|
16
|
+
If you're not brave enough, you can limit the group not to include `production` environment.
|
17
|
+
Indeed, enabling this gem for the processes like batch or job may improve their runtime performance, but so far as that's not a critical problem for your production system, the following setup might be safer.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
group :development, :test do
|
21
|
+
gem 'routes_lazy_routes'
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
You have nothing to do with it. It should just work beneath the skin.
|
29
|
+
|
30
|
+
|
31
|
+
## Trade-off
|
32
|
+
|
33
|
+
The first visitor of the server should sacrifice their time for the Rails process to load the routes.
|
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
|
+
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Patches are welcome on GitHub at https://github.com/amatsuda/routes_lazy_routes.
|
40
|
+
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "routes_lazy_routes"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'routes_lazy_routes/version'
|
4
|
+
require_relative 'routes_lazy_routes/lazy_routes_middleware'
|
5
|
+
require_relative 'routes_lazy_routes/routes_reloader_wrapper'
|
6
|
+
require_relative 'routes_lazy_routes/railtie'
|
7
|
+
|
8
|
+
module RoutesLazyRoutes
|
9
|
+
class << self
|
10
|
+
# The root of evil
|
11
|
+
def arise!
|
12
|
+
Rails::Application::RoutesReloader.class_eval do
|
13
|
+
class << self
|
14
|
+
def new
|
15
|
+
RoutesLazyRoutes::RoutesReloaderWrapper.new super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RoutesLazyRoutes
|
4
|
+
class LazyRoutesMiddleware
|
5
|
+
def initialize(app, original_routes_reloader)
|
6
|
+
@app = app
|
7
|
+
@original_routes_reloader = original_routes_reloader
|
8
|
+
@mutex = Mutex.new
|
9
|
+
@loaded = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
unless @loaded
|
14
|
+
@mutex.synchronize do
|
15
|
+
@app.instance_variable_set :@routes_reloader, @original_routes_reloader
|
16
|
+
@original_routes_reloader.execute
|
17
|
+
@loaded = true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
@app.call env
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RoutesLazyRoutes
|
4
|
+
class RoutesReloaderWrapper
|
5
|
+
delegate :paths, :eager_load=, :updated?, :route_sets, to: :@original_routes_reloader
|
6
|
+
|
7
|
+
def initialize(original_routes_reloader)
|
8
|
+
@original_routes_reloader = original_routes_reloader
|
9
|
+
|
10
|
+
Rails.application.config.middleware.use LazyRoutesMiddleware, original_routes_reloader
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute
|
14
|
+
# pretty vacant
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/routes_lazy_routes/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "routes_lazy_routes"
|
7
|
+
spec.version = RoutesLazyRoutes::VERSION
|
8
|
+
spec.authors = ["Akira Matsuda"]
|
9
|
+
spec.email = ["ronnie@dio.jp"]
|
10
|
+
|
11
|
+
spec.summary = 'A Rails routes lazy loader'
|
12
|
+
spec.description = 'A Rails plugin that defers loading the whole bloody routes so the app can spin up quickly'
|
13
|
+
spec.homepage = 'https://github.com/amatsuda/routes_lazy_routes'
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = 'https://github.com/amatsuda/routes_lazy_routes'
|
19
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_dependency 'rails'
|
29
|
+
spec.add_development_dependency 'byebug'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: routes_lazy_routes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akira Matsuda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
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: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A Rails plugin that defers loading the whole bloody routes so the app
|
42
|
+
can spin up quickly
|
43
|
+
email:
|
44
|
+
- ronnie@dio.jp
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".github/workflows/main.yml"
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- MIT-LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- lib/routes_lazy_routes.rb
|
58
|
+
- lib/routes_lazy_routes/lazy_routes_middleware.rb
|
59
|
+
- lib/routes_lazy_routes/railtie.rb
|
60
|
+
- lib/routes_lazy_routes/routes_reloader_wrapper.rb
|
61
|
+
- lib/routes_lazy_routes/version.rb
|
62
|
+
- routes_lazy_routes.gemspec
|
63
|
+
homepage: https://github.com/amatsuda/routes_lazy_routes
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata:
|
67
|
+
homepage_uri: https://github.com/amatsuda/routes_lazy_routes
|
68
|
+
source_code_uri: https://github.com/amatsuda/routes_lazy_routes
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.3.0
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.2.0.rc.2
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: A Rails routes lazy loader
|
88
|
+
test_files: []
|