Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails exclude folder from auto/eager load

I want to scale separately some subparts of my rails app and avoid loading the whole codebase.

For the sake of example, let's consider an APIv1 vs an APIv2, but I'd also want to extend this any class/service in general

Is it possible to exclude a specific folder from the eager load (production) or autoload (in dev) ?

For example,

api-v1-productionenvironment should exclude

controllers/api/v[^1]/**/*.rb

api-v2-productionenvironment should exclude

controllers/api/v[^2]/**/*.rb

I am writing [^x] as a convenient notation for everything but x) for the sake of example

I know it is possible to add some autoload/eager load folders but what about excluding some instead ? (especially if they are inside app/ which is autoloaded/eager loaded by default)

I want to avoid loading in memory too many classes/services, etc. that I know won't be useful

like image 807
Cyril Duchon-Doris Avatar asked May 03 '26 12:05

Cyril Duchon-Doris


1 Answers

I hope that 3 years later you may have already found the solution. Anyway...

You may try this:

  • api-v1-production

Add this to your config/environments/api-v1-production:

config.eager_load_paths -= ["#{config.root}/app/controllers/api/v[^2]"]
  • api-v2-production

Add this to your config/environments/api-v2-production:

config.eager_load_paths -= ["#{config.root}/app/controllers/api/v[^2]"]

Hope it works.

like image 62
João Fernandes Avatar answered May 06 '26 02:05

João Fernandes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!