mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Better use of index when queueing a topci for search reindex.
Also move `Search::INDEX_VERSION` to `SearchIndexer` which is where the version is actually being used.
This commit is contained in:
@@ -25,7 +25,7 @@ describe Jobs::ReindexSearch do
|
||||
model.reload
|
||||
|
||||
subject.execute({})
|
||||
expect(model.send("#{m}_search_data").version).to eq Search::INDEX_VERSION
|
||||
expect(model.send("#{m}_search_data").version).to eq SearchIndexer::INDEX_VERSION
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,6 +3,14 @@ require 'rails_helper'
|
||||
describe SearchIndexer do
|
||||
let(:post_id) { 99 }
|
||||
|
||||
before do
|
||||
SearchIndexer.enable
|
||||
end
|
||||
|
||||
after do
|
||||
SearchIndexer.disable
|
||||
end
|
||||
|
||||
def scrub(html, strip_diacritics: false)
|
||||
SearchIndexer.scrub_html_for_search(html, strip_diacritics: strip_diacritics)
|
||||
end
|
||||
@@ -75,7 +83,7 @@ describe SearchIndexer do
|
||||
raw_data, locale, version = PostSearchData.where(post_id: post_id).pluck(:raw_data, :locale, :version)[0]
|
||||
expect(raw_data).to eq("This is a test")
|
||||
expect(locale).to eq("en")
|
||||
expect(version).to eq(Search::INDEX_VERSION)
|
||||
expect(version).to eq(SearchIndexer::INDEX_VERSION)
|
||||
|
||||
SearchIndexer.update_posts_index(post_id, "tester", "", nil, nil)
|
||||
|
||||
@@ -86,14 +94,6 @@ describe SearchIndexer do
|
||||
describe '.index' do
|
||||
let(:post) { Fabricate(:post) }
|
||||
|
||||
before do
|
||||
SearchIndexer.enable
|
||||
end
|
||||
|
||||
after do
|
||||
SearchIndexer.disable
|
||||
end
|
||||
|
||||
it 'should index posts correctly' do
|
||||
expect { post }.to change { PostSearchData.count }.by(1)
|
||||
|
||||
@@ -153,4 +153,23 @@ describe SearchIndexer do
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.queue_post_reindex' do
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:topic) { post.topic }
|
||||
|
||||
it 'should reset the version of search data for all posts in the topic' do
|
||||
post2 = Fabricate(:post)
|
||||
|
||||
SearchIndexer.queue_post_reindex(topic.id)
|
||||
|
||||
expect(post.reload.post_search_data.version).to eq(
|
||||
SearchIndexer::REINDEX_VERSION
|
||||
)
|
||||
|
||||
expect(post2.reload.post_search_data.version).to eq(
|
||||
SearchIndexer::INDEX_VERSION
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user