From 18d652c8f0cce62669f2cdf7d9c6a73a9f3d2da5 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 29 Jan 2024 09:57:58 +0800 Subject: [PATCH] DEV: Create unlogged tables by default in the test environment (#25451) Why this change? In https://www.postgresql.org/docs/current/non-durability.html, it is recommended to create unlogged tables to avoid WAL writes which can help speed at performance at the expense of durability. In the CI env, there is no need for durability at all. Therefore, we are going to be creating unlogged tables by default. Co-authored-by: Ted Johansson Co-authored-by: Rafael dos Santos Silva --- .github/workflows/tests.yml | 1 + config/environments/test.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5d12faea8c0..c2b79b3a1cd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -145,6 +145,7 @@ jobs: ${{ runner.os }}- ${{ hashFiles('.github/workflows/tests.yml') }}- ${{ hashFiles('db/**/*', 'plugins/**/db/**/*') }}- + ${{ hashFiles('config/environments/test.rb') }}- ${{ env.USES_PARALLEL_DATABASES }} - name: Restore database from cache diff --git a/config/environments/test.rb b/config/environments/test.rb index cb3edca1239..587a79b8a04 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -104,4 +104,10 @@ Discourse::Application.configure do SiteSetting.refresh! end + + if ENV["CI"].present? + config.to_prepare do + ActiveSupport.on_load(:active_record_postgresqladapter) { self.create_unlogged_tables = true } + end + end end