A platform for community discussion. Free, open, simple.
DEV: Improve `bin/unicorn` boot time in development environment (#12900)
David Taylorcac7725e28ee
diff --git a/config/unicorn.conf.rb b/config/unicorn.conf.rbindex 44e67354214..ffcafcb618d 100644--- a/config/unicorn.conf.rb+++ b/config/unicorn.conf.rb@@ -251,18 +251,19 @@ before_fork do |server, worker|# to the implementation of standard Unix signal handlers, this# helps (but does not completely) prevent identical, repeated signals# from being lost when the receiving process is busy.- sleep 1+ sleep 1 if !Rails.env.development?endafter_fork do |server, worker|DiscourseEvent.trigger(:web_fork_started)+ Discourse.after_fork# warm up v8 after fork, that way we do not fork a v8 context# it may cause issues if bg threads in a v8 isolate randomly stop# working due to fork- Discourse.after_forkbegin- PrettyText.cook("warm up **pretty text**")+ # Skip warmup in development mode - it makes boot take ~2s longer+ PrettyText.cook("warm up **pretty text**") if !Rails.env.development?rescue => eRails.logger.error("Failed to warm up pretty text: #{e}")enddiff --git a/lib/discourse.rb b/lib/discourse.rbindex a04949fe538..a3ae1ad2bde 100644--- a/lib/discourse.rb+++ b/lib/discourse.rb@@ -903,14 +903,19 @@ module Discoursedef self.preload_rails!return if @preloaded_rails- # load up all models and schema- (ActiveRecord::Base.connection.tables - %w[schema_migrations versions]).each do |table|- table.classify.constantize.first rescue nil- end+ if !Rails.env.development?+ # Skipped in development because the schema cache gets reset on every code change anyway+ # Better to rely on the filesystem-based db:schema:cache:dump- # ensure we have a full schema cache in case we missed something above- ActiveRecord::Base.connection.data_sources.each do |table|- ActiveRecord::Base.connection.schema_cache.add(table)+ # load up all models and schema+ (ActiveRecord::Base.connection.tables - %w[schema_migrations versions]).each do |table|+ table.classify.constantize.first rescue nil+ end++ # ensure we have a full schema cache in case we missed something above+ ActiveRecord::Base.connection.data_sources.each do |table|+ ActiveRecord::Base.connection.schema_cache.add(table)+ endendschema_cache = ActiveRecord::Base.connection.schema_cache