Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does adding files to the app directory make the server slow?

I cannot seem to find any information on this.

In my app folder (where I have models, views, controllers folders etc) I created a subdirectory app/data where I put about 10,000 files. After that, my Rails development server was incredibly slow.

What is the reason for this? Can I configure Rails to ignore certain files/folders? I take it it's to do with the dynamic nature of Ruby/Rails?

like image 659
jmasterx Avatar asked Dec 20 '22 03:12

jmasterx


2 Answers

If you add a dir directly under app/, all files in this dir are eager loaded in production and lazy loaded in development by default.

Try adding this in config/initializer.rb:

path = Rails.root + "app/data"
ActiveSupport::Dependencies.autoload_paths -= [path.to_s]

This is to remove add/data from autoload path.

like image 55
Pardeep Dhingra Avatar answered May 18 '23 16:05

Pardeep Dhingra


Well, previous answer is correct, but as for me it's better to put this stuff somewhere else, because it's definitely not application code and, for example, it shouldn't be added to git.

like image 36
kimrgrey Avatar answered May 18 '23 18:05

kimrgrey