CP-11414 skip search indexing for partnership templates (#27)

* skip search indexing for partnership templates

* added a guard clause to prevent search indexing of templates without an account_id, specifically for partnership templates. This avoids unnecessary indexing since search is not currently used for partnerships.

* add search entry spec
pull/544/head
Ryan Arakawa 2 months ago committed by GitHub
parent 741c548d26
commit 5cf66205a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -180,6 +180,11 @@ module SearchEntries
end
def index_template(template)
# Skip search indexing for partnership templates since they don't belong to accounts
# We currently don't utilize search, so this can be implemented later for partnerships
# if that changes.
return if template.account_id.blank?
sql = SearchEntry.sanitize_sql_array(
["SELECT to_tsvector(:text), to_tsvector('simple', :text)",
{ text: TextUtils.transliterate(template.name.to_s.downcase).delete("\0") }]

@ -0,0 +1,47 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe SearchEntries do
describe '.index_template' do
context 'with partnership template' do
let(:partnership) { create(:partnership) }
let(:template) do
create(:template, :partnership_template, partnership: partnership, name: 'Partnership Template')
end
it 'skips search indexing for partnership templates' do
result = described_class.index_template(template)
expect(result).to be_nil
expect(template.reload.search_entry).to be_nil
end
it 'does not raise error when account_id is blank' do
expect { described_class.index_template(template) }.not_to raise_error
end
it 'logs the reason for skipping partnership templates' do
# Verify the early return works as expected
expect(template.account_id).to be_nil
expect(template.partnership_id).to be_present
result = described_class.index_template(template)
expect(result).to be_nil
end
end
context 'with account template' do
let(:account) { create(:account) }
let(:user) { create(:user, account: account) }
let(:template) { create(:template, account: account, author: user, name: 'Test Template') }
it 'processes account templates normally' do
expect(template.account_id).to be_present
expect(template.partnership_id).to be_nil
expect { described_class.index_template(template) }.not_to raise_error(ArgumentError, /account_id.blank?/)
end
end
end
end
Loading…
Cancel
Save