fix: bump inbox cache when portal changes
The cached inbox payload embeds the portal name and slug as help_center, but portal updates and deletes never bumped the inbox cache key, so warm IDB caches kept showing stale help-center details. Bump the account inbox cache key from the portal lifecycle; destroy is covered because nullify detaches inboxes via update_all and skips their callbacks.
This commit is contained in:
@@ -50,6 +50,13 @@ class Portal < ApplicationRecord
|
||||
schema: PortalConfigSchema::CONFIG_PARAMS_SCHEMA,
|
||||
attribute_resolver: ->(record) { record.config }
|
||||
|
||||
# Portal name/slug are embedded as help_center into the cached inbox payload
|
||||
# (api/v1/models/_inbox.json.jbuilder), so portal changes must bump the
|
||||
# account's inbox cache key. Destroy is covered too: dependent: :nullify
|
||||
# detaches inboxes via update_all and skips their callbacks.
|
||||
after_update_commit -> { account.update_cache_key('inbox') }
|
||||
after_destroy_commit -> { account.update_cache_key('inbox') }
|
||||
|
||||
scope :active, -> { where(archived: false) }
|
||||
|
||||
# TODO: 'website_token' is an unused reserved key; remove with a migration that scrubs it from existing portals' config
|
||||
|
||||
@@ -150,4 +150,22 @@ RSpec.describe Portal do
|
||||
expect(portal.display_title).to eq('Help Center | Acme')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'inbox cache invalidation' do
|
||||
# Portal name/slug are embedded as help_center into the cached inbox
|
||||
# payload (api/v1/models/_inbox.json.jbuilder), so portal changes must bump
|
||||
# the account's inbox cache key.
|
||||
let(:account) { create(:account) }
|
||||
let!(:portal) { create(:portal, account: account) }
|
||||
|
||||
it 'bumps the inbox cache key after update' do
|
||||
expect(account).to receive(:update_cache_key).with('inbox')
|
||||
portal.update!(name: 'Renamed Portal')
|
||||
end
|
||||
|
||||
it 'bumps the inbox cache key after destroy' do
|
||||
expect(account).to receive(:update_cache_key).with('inbox')
|
||||
portal.destroy!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user