PERF: Create a partial regular post_search_data index on large sites.

With the addition of `PostSearchData#private_message`, a partial
index consisting of only search data from regular posts can be created.
The partial index helps to speed up searches on large sites since PG
will not have to do an index scan on the entire search data index which
has shown to be a bottle neck.
This commit is contained in:
Guo Xiang Tan
2020-08-21 16:16:28 +08:00
committed by Alan Guo Xiang Tan
parent f7314f8ab4
commit 40c6d90df3
5 changed files with 126 additions and 17 deletions

View File

@@ -0,0 +1,45 @@
# frozen_string_literal: true
require 'rails_helper'
describe Jobs::CreateRecentPostSearchIndexes do
subject { described_class.new }
fab!(:post) do
SearchIndexer.enable
Fabricate(:post)
end
fab!(:post_2) do
SearchIndexer.enable
Fabricate(:post)
end
before do
SearchIndexer.enable
end
describe '#execute' do
it 'should not create the index if requried posts size has not been reached' do
SiteSetting.search_recent_posts_size = 1
SiteSetting.search_enable_recent_regular_posts_offset_size = 3
expect do
subject.execute({})
end.to_not change { SiteSetting.search_recent_regular_posts_offset_post_id }
end
it 'should create the right index' do
SiteSetting.search_recent_posts_size = 1
SiteSetting.search_enable_recent_regular_posts_offset_size = 1
subject.execute({})
expect(SiteSetting.search_recent_regular_posts_offset_post_id).to eq(post_2.id)
expect(DB.query_single(<<~SQL).first).to eq(1)
SELECT 1 FROM pg_indexes WHERE indexname = '#{described_class::REGULAR_POST_SEARCH_DATA_INDEX_NAME}'
SQL
end
end
end