Skip to content

A platform for community discussion. Free, open, simple.

DEV: Speed up CI annotation and structure checks (#41614)

Alan Guo Xiang Tane47a85ce8c80
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index ecb8af4b0ce..07a619136b4 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -214,7 +214,7 @@ jobs:
directories="$(script/list_bundled_plugins | xargs -I{} find {} -type d -path '*/app/models' -maxdepth 3)"
fi
- # annotate:clean runs the seed + annotaterb in a temporary postgres so it
+ # annotate:clean runs index setup + annotaterb in a temporary postgres so it
# doesn't pollute the rspec test DB.
MODEL_DIR="$(echo "${directories}" | tr '\n' ',')" bin/rake annotate:clean
diff --git a/lib/tasks/annotate.rake b/lib/tasks/annotate.rake
index 15f9759b60a..2e36d1791ae 100644
--- a/lib/tasks/annotate.rake
+++ b/lib/tasks/annotate.rake
@@ -1,14 +1,18 @@
# frozen_string_literal: true
-# Runs annotaterb in a TemporaryDb so the seed topics that
-# `annotate:ensure_all_indexes` creates don't leak into the persistent test DB.
+# Runs annotaterb in a TemporaryDb so the index setup performed by
+# `annotate:ensure_all_indexes` does not leak into the persistent test DB.
def annotate_in_temp_db(load_plugins:, annotaterb_args: [])
- env = { "RAILS_ENV" => "test", "LOAD_PLUGINS" => load_plugins }
+ env = {
+ "RAILS_ENV" => "test",
+ "LOAD_PLUGINS" => load_plugins,
+ "SKIP_OPTIMIZE_ICONS" => "1",
+ "SKIP_SEED_FU" => "1",
+ }
db = TemporaryDb.new
db.start
db.with_env do
- system(env, "bin/rails", "db:migrate", exception: true)
- system(env, "bin/rails", "annotate:ensure_all_indexes", exception: true)
+ system(env, "bin/rails", "db:migrate", "annotate:ensure_all_indexes", exception: true)
system(env, "bin/annotaterb", "models", "--force", *annotaterb_args, exception: true)
end
ensure
@@ -31,11 +35,25 @@ end
desc "ensure the asynchronously-created post_search_data index is present"
task "annotate:ensure_all_indexes" => :environment do |task, args|
- # One of the indexes on post_search_data is created by a sidekiq job
- # We need to do some acrobatics to create it on-demand
- SeedData::Topics.with_default_locale.create
- SiteSetting.search_enable_recent_regular_posts_offset_size = 1
- Jobs::CreateRecentPostSearchIndexes.new.execute([])
+ recent_posts_size = SiteSetting.search_recent_posts_size
+ offset_size = SiteSetting.search_enable_recent_regular_posts_offset_size
+ offset_post_id = SiteSetting.search_recent_regular_posts_offset_post_id
+ inserted_synthetic_row = false
+
+ # One of the indexes on post_search_data is created by a sidekiq job.
+ # Add the minimum data needed to create it on demand.
+ begin
+ PostSearchData.insert_all!([{ post_id: 0, private_message: false }])
+ inserted_synthetic_row = true
+ SiteSetting.search_enable_recent_regular_posts_offset_size = 1
+ SiteSetting.search_recent_posts_size = 1
+ Jobs::CreateRecentPostSearchIndexes.new.execute([])
+ ensure
+ PostSearchData.where(post_id: 0).delete_all if inserted_synthetic_row
+ SiteSetting.search_enable_recent_regular_posts_offset_size = offset_size
+ SiteSetting.search_recent_posts_size = recent_posts_size
+ SiteSetting.search_recent_regular_posts_offset_post_id = offset_post_id
+ end
end
desc "regenerate core model annotations using a temporary database"
diff --git a/lib/temporary_db.rb b/lib/temporary_db.rb
index 450264a6f9d..5b9f1206c8c 100644
--- a/lib/temporary_db.rb
+++ b/lib/temporary_db.rb
@@ -96,7 +96,7 @@ class TemporaryDb
def start
init_data_directory
- configure_ports
+ configure_database
puts "Starting postgres on port: #{pg_port}"
@previous_discourse_pg_port = ENV["DISCOURSE_PG_PORT"]
@@ -192,11 +192,21 @@ class TemporaryDb
)
end
- def configure_ports
+ def configure_database
FileUtils.mkdir(@pg_sock_path)
FileUtils.chown(@pg_system_user, nil, @pg_sock_path) if running_as_root?
conf = File.read(@pg_conf)
- File.write(@pg_conf, conf + "\nport = #{pg_port}\nunix_socket_directories = '#{@pg_sock_path}'")
+ conf << <<~CONF
+
+ port = #{pg_port}
+ unix_socket_directories = '#{@pg_sock_path}'
+ fsync = off
+ synchronous_commit = off
+ full_page_writes = off
+ wal_level = minimal
+ max_wal_senders = 0
+ CONF
+ File.write(@pg_conf, conf)
end
def start_server