Add caching for payload serialization during fan-out (#19642)
This commit is contained in:
parent
b8f6f03956
commit
5f9e47be34
5 changed files with 129 additions and 7 deletions
54
spec/lib/status_cache_hydrator_spec.rb
Normal file
54
spec/lib/status_cache_hydrator_spec.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe StatusCacheHydrator do
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
describe '#hydrate' do
|
||||
subject { described_class.new(status).hydrate(account.id) }
|
||||
|
||||
let(:compare_to_hash) { InlineRenderer.render(status, account, :status) }
|
||||
|
||||
context 'when cache is warm' do
|
||||
before do
|
||||
Rails.cache.write("fan-out/#{status.id}", InlineRenderer.render(status, nil, :status))
|
||||
end
|
||||
|
||||
it 'renders the same attributes as a full render' do
|
||||
expect(subject).to include(compare_to_hash)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when cache is cold' do
|
||||
before do
|
||||
Rails.cache.delete("fan-out/#{status.id}")
|
||||
end
|
||||
|
||||
it 'renders the same attributes as a full render' do
|
||||
expect(subject).to include(compare_to_hash)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account has favourited status' do
|
||||
before do
|
||||
FavouriteService.new.call(account, status)
|
||||
end
|
||||
|
||||
it 'renders the same attributes as a full render' do
|
||||
expect(subject).to include(compare_to_hash)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account has reblogged status' do
|
||||
before do
|
||||
ReblogService.new.call(account, status)
|
||||
end
|
||||
|
||||
it 'renders the same attributes as a full render' do
|
||||
expect(subject).to include(compare_to_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue