Improve counter caches on Status and Account (#7644)
Do not touch statuses_count on accounts table when mass-destroying statuses to reduce load when removing accounts, same for reblogs_count and favourites_count Do not count statuses with direct visibility in statuses_count Fix #828
This commit is contained in:
parent
461542784b
commit
a7d726c383
6 changed files with 126 additions and 7 deletions
|
@ -175,6 +175,13 @@ RSpec.describe Status, type: :model do
|
|||
|
||||
expect(subject.reblogs_count).to eq 2
|
||||
end
|
||||
|
||||
it 'is decremented when reblog is removed' do
|
||||
reblog = Fabricate(:status, account: bob, reblog: subject)
|
||||
expect(subject.reblogs_count).to eq 1
|
||||
reblog.destroy
|
||||
expect(subject.reblogs_count).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
describe '#favourites_count' do
|
||||
|
@ -184,6 +191,13 @@ RSpec.describe Status, type: :model do
|
|||
|
||||
expect(subject.favourites_count).to eq 2
|
||||
end
|
||||
|
||||
it 'is decremented when favourite is removed' do
|
||||
favourite = Fabricate(:favourite, account: bob, status: subject)
|
||||
expect(subject.favourites_count).to eq 1
|
||||
favourite.destroy
|
||||
expect(subject.favourites_count).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
describe '#proper' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue