Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

routes_lazy_routes

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

routes_lazy_routes

  • 0.4.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

routes_lazy_routes

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. 🤘

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.

Installation

Add this line to your application's Gemfile:

gem 'routes_lazy_routes'

If you're not brave enough, you can limit the group not to include production environment. 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.

group :development, :test do
  gem 'routes_lazy_routes'
end

Usage

You have nothing to do with it. It should just work beneath the skin.

Trade-off

The first visitor of the server should sacrifice their time for the Rails process to load the routes. First strike is deadly. 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.

Notes

  • You can manually eager_load the routes by calling RoutesLazyRoutes.eager_load! (the "load runner").

  • Rails.application.eager_load! automatically invokes RoutesLazyRoutes.eager_load! since that should be what we expect for Rails.application.eager_load!.

  • Loading an integration test automatically kicks RoutesLazyRoutes.eager_load! since AD::Integration expects the routes to be loaded.

  • And, as already explained, sending a request to the Rails server automatically runs RoutesLazyRoutes.eager_load! on the server.

  • On the other hand, you need manually calling RoutesLazyRoutes.eager_load! inside your worker process (e.g. Sidekiq) to resolve named routes like the following:

    # config/initializers/sidekiq.rb
    Sidekiq.configure_server do |config|
      if defined?(RoutesLazyRoutes)
        Rails.application.config.after_initialize do
          RoutesLazyRoutes.eager_load!
        end
      end
    end
    

Contributing

Patches are welcome on GitHub at https://github.com/amatsuda/routes_lazy_routes.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 23 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc