discourse/spec/jobs/index_user_fields_for_search_spec.rb
Natalie Tay 00a9369ca2
FIX: Move user reindexing into a job (#26753)
In a large forum with millions of users and millions of user_fields
updating the list of dropdown user field options will result in a
502 now due to the large number of fields.

This commit moves the indexing into a job.
2024-04-25 20:58:34 +08:00

21 lines
530 B
Ruby

# frozen_string_literal: true
RSpec.describe Jobs::IndexUserFieldsForSearch do
subject(:job) { described_class.new }
before do
SearchIndexer.enable
Jobs.run_immediately!
end
it "triggers a reindex when executed" do
user = Fabricate(:user)
user_field = Fabricate(:user_field)
Fabricate(:user_custom_field, user: user, name: "user_field_#{user_field.id}")
job.execute(user_field_id: user_field.id)
expect(user.reload.user_search_data.version).to eq(SearchIndexer::REINDEX_VERSION)
end
end