DEV: Use filesystem-based SchemaCache in development (#12901)

In development we regularly restart/reload Rails, which wipes out the schema cache. This then has to be regenerated using DDL queries on the database.

Instead, we can make use of the `rake db:schema:cache:dump` command. This will dump the schema cache to a YAML file, and then load it when needed. This is significantly faster than rebuilding the cache from DDL queries every time.
This commit is contained in:
David Taylor 2021-04-30 10:54:49 +01:00 committed by GitHub
parent ed818a4a19
commit ad8c7714c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 0 deletions

1
.gitignore vendored
View File

@ -36,6 +36,7 @@ config/discourse.conf
/db/*.sqlite3
/db/structure.sql
/db/schema.rb
/db/schema_cache.yml
# Ignore all logfiles and tempfiles.
/log/*.log

View File

@ -235,6 +235,9 @@ module Discourse
# see: http://stackoverflow.com/questions/11894180/how-does-one-correctly-add-custom-sql-dml-in-migrations/11894420#11894420
config.active_record.schema_format = :sql
# We use this in development-mode only (see development.rb)
config.active_record.use_schema_cache_dump = false
# per https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet
config.pbkdf2_iterations = 64000
config.pbkdf2_algorithm = "sha256"

View File

@ -12,6 +12,9 @@ Discourse::Application.configure do
# Log error messages when you accidentally call methods on nil.
config.eager_load = false
# Use the schema_cache.yml file generated during db:migrate (via db:schema:cache:dump)
config.active_record.use_schema_cache_dump = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

View File

@ -221,6 +221,10 @@ task 'db:migrate' => ['load_config', 'environment', 'set_locale'] do |_, args|
SeedFu.quiet = true
SeedFu.seed(SeedHelper.paths, SeedHelper.filter)
if Rails.env.development?
Rake::Task['db:schema:cache:dump'].invoke
end
if !Discourse.skip_post_deployment_migrations? && ENV['SKIP_OPTIMIZE_ICONS'] != '1'
SiteIconManager.ensure_optimized!
end