0
0
Fork 0

Fix performance of percentile calculation for annual reports (#32765)

This commit is contained in:
Eugen Rochko 2024-11-04 11:11:06 +01:00 committed by GitHub
parent 823f597f00
commit 90f4ffa31d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 77 additions and 47 deletions

View file

@ -4,17 +4,20 @@ require 'rails_helper'
RSpec.describe AnnualReport::Percentiles do
describe '#generate' do
subject { described_class.new(account, Time.zone.now.year) }
subject { described_class.new(account, year) }
let(:year) { Time.zone.now.year }
context 'with an inactive account' do
let(:account) { Fabricate :account }
it 'builds a report for an account' do
described_class.prepare(year)
expect(subject.generate)
.to include(
percentiles: include(
followers: 0,
statuses: 0
statuses: 100
)
)
end
@ -25,16 +28,15 @@ RSpec.describe AnnualReport::Percentiles do
before do
Fabricate.times 2, :status # Others as `account`
Fabricate.times 2, :follow # Others as `target_account`
Fabricate.times 2, :status, account: account
Fabricate.times 2, :follow, target_account: account
end
it 'builds a report for an account' do
described_class.prepare(year)
expect(subject.generate)
.to include(
percentiles: include(
followers: 50,
statuses: 50
)
)