diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-08-24 14:35:21 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-08-24 20:22:16 +0200 |
commit | 167b9b81440017f5253efda4bb6566d12f0eedc8 (patch) | |
tree | eadc56ab63940fbaa6abbd9d3267b983c0adaf4b | |
parent | c8406ec3bf57acbaee8413772091ffc5ee9a30fb (diff) | |
download | gitlab-ce-schema-cache.tar.gz |
Enable caching of schema.rbschema-cache
This is a lesser known Rails feature that removes the need for querying
various internal tables for schema details (e.g. column types) every
time Rails boots up.
This feature is described in http://iempire.ru/2016/12/13/schema-cache/
and was brought to our attention by @stanhu.
Since the schema cache is specific to the database we only enable this
on PostgreSQL.
-rw-r--r-- | .gitlab/merge_request_templates/Database Changes.md | 1 | ||||
-rw-r--r-- | changelogs/unreleased/schema-cache.yml | 5 | ||||
-rw-r--r-- | config/application.rb | 5 | ||||
-rw-r--r-- | db/schema.rb | 8 | ||||
-rw-r--r-- | db/schema_cache.dump | bin | 0 -> 93876 bytes | |||
-rw-r--r-- | lib/tasks/db.rake | 7 |
6 files changed, 22 insertions, 4 deletions
diff --git a/.gitlab/merge_request_templates/Database Changes.md b/.gitlab/merge_request_templates/Database Changes.md index 2a5c8267872..1e74f70d2ed 100644 --- a/.gitlab/merge_request_templates/Database Changes.md +++ b/.gitlab/merge_request_templates/Database Changes.md @@ -21,6 +21,7 @@ measurements there, and include the results in this MR. When adding migrations: - [ ] Updated `db/schema.rb` +- [ ] Updated `db/schema_cache.dump` - [ ] Added a `down` method so the migration can be reverted - [ ] Added the output of the migration(s) to the MR body - [ ] Added the execution time of the migration(s) to the MR body diff --git a/changelogs/unreleased/schema-cache.yml b/changelogs/unreleased/schema-cache.yml new file mode 100644 index 00000000000..61f6e56f4cf --- /dev/null +++ b/changelogs/unreleased/schema-cache.yml @@ -0,0 +1,5 @@ +--- +title: Enable caching of schema.rb +merge_request: +author: +type: other diff --git a/config/application.rb b/config/application.rb index f69dab4de39..68dc449b793 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,6 +10,7 @@ module Gitlab require_dependency Rails.root.join('lib/gitlab/redis/queues') require_dependency Rails.root.join('lib/gitlab/redis/shared_state') require_dependency Rails.root.join('lib/gitlab/request_context') + require_dependency Rails.root.join('lib/gitlab/database') # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers @@ -156,6 +157,10 @@ module Gitlab config.active_record.raise_in_transactional_callbacks = true + # The schema cache is database specific. There is no way to support both + # PostgreSQL and MySQL, hence we only enable this when PostgreSQL is used. + config.active_record.use_schema_cache_dump = Gitlab::Database.postgresql? + config.active_job.queue_adapter = :sidekiq # This is needed for gitlab-shell diff --git a/db/schema.rb b/db/schema.rb index cd488630237..13c741bb8dd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170820100558) do +ActiveRecord::Schema.define(version: 20170824162758) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -34,7 +34,7 @@ ActiveRecord::Schema.define(version: 20170820100558) do t.string "logo" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.text "description_html", null: false + t.text "description_html" t.integer "cached_markdown_version" end @@ -279,8 +279,8 @@ ActiveRecord::Schema.define(version: 20170820100558) do t.string "encrypted_value_salt" t.string "encrypted_value_iv" t.integer "pipeline_schedule_id", null: false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "ci_pipeline_schedule_variables", ["pipeline_schedule_id", "key"], name: "index_ci_pipeline_schedule_variables_on_schedule_id_and_key", unique: true, using: :btree diff --git a/db/schema_cache.dump b/db/schema_cache.dump Binary files differnew file mode 100644 index 00000000000..197014c1471 --- /dev/null +++ b/db/schema_cache.dump diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake new file mode 100644 index 00000000000..664e75494b8 --- /dev/null +++ b/lib/tasks/db.rake @@ -0,0 +1,7 @@ +namespace :db do + namespace :schema do + task 'dump' do + Rake::Task['db:schema:cache:dump'].invoke + end + end +end |