News for hackers. Stuff that matters.
Re:Reducing Memory Usage in Ruby by AznHisoka on Tuesday January 23, 2018 @09:53PM (#16219953)
I am actually facing a similar problem. I also find that Rails just creates a db connection everytime I do Model.new even though I have not yet saved it.
Re:Reducing Memory Usage in Ruby by amichal on Tuesday January 23, 2018 @11:31PM (#16220329)
This is because active record models learn their attributes by querying the database scheme. I haven’t tried it but there appears to be a way to cache this information in the local file system which would likely avoid the early dB connect if you really needed to do that. Also avoids querying the scheme on processs boot entirely if you are willing to trust the cached scheme matches the. database scheme. See https://github.com/rails/rails/issues/24133 for discussion