9

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

Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164

1 Answers1

0

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.

João Fernandes
  • 673
  • 1
  • 5
  • 15