Compare commits

...

4 Commits

Author SHA1 Message Date
Matt Jankowski
341c63c1ad
Merge cf175114d7 into 74fc4dbacf 2025-07-15 17:05:58 +00:00
diondiondion
74fc4dbacf
refactor: Only remove pointer-events when necessary (#35390)
Some checks failed
Check i18n / check-i18n (push) Waiting to run
Chromatic / Run Chromatic (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Crowdin / Upload translations / upload-translations (push) Has been cancelled
Haml Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
2025-07-15 15:57:31 +00:00
Matt Jankowski
cf175114d7 Brakeman warns on implicit to_s result 2025-07-11 11:16:17 -04:00
Matt Jankowski
8271e9af4c Move annual report percentile data update to model class 2025-07-11 10:34:14 -04:00
6 changed files with 82 additions and 23 deletions

View File

@ -2848,7 +2848,6 @@ a.account__display-name {
&__pane {
height: 100%;
overflow: hidden;
pointer-events: none;
display: flex;
justify-content: flex-end;
min-width: 285px;
@ -2860,7 +2859,6 @@ a.account__display-name {
&__inner {
position: fixed;
width: 285px;
pointer-events: auto;
height: 100%;
}
}

View File

@ -2,15 +2,7 @@
class AnnualReport::Percentiles < AnnualReport::Source
def self.prepare(year)
AnnualReport::StatusesPerAccountCount.connection.exec_query(<<~SQL.squish, nil, [year, Mastodon::Snowflake.id_at(DateTime.new(year).beginning_of_year), Mastodon::Snowflake.id_at(DateTime.new(year).end_of_year)])
INSERT INTO annual_report_statuses_per_account_counts (year, account_id, statuses_count)
SELECT $1, account_id, count(*)
FROM statuses
WHERE id BETWEEN $2 AND $3
AND (local OR uri IS NULL)
GROUP BY account_id
ON CONFLICT (year, account_id) DO NOTHING
SQL
AnnualReport::StatusesPerAccountCount.refresh(year)
end
def generate

View File

@ -11,5 +11,35 @@
#
class AnnualReport::StatusesPerAccountCount < ApplicationRecord
# This table facilitates percentile calculations
def self.refresh(year)
connection.exec_query(<<~SQL.squish)
INSERT INTO #{table_name} (year, account_id, statuses_count)
#{AccountStatusCountQuery.new(year).to_sql}
ON CONFLICT (year, account_id) DO NOTHING
SQL
end
class AccountStatusCountQuery
def initialize(year)
@year = year
end
def to_sql
Status
.unscoped
.local
.where(id: beginning_of_year..end_of_year)
.group(:account_id)
.select(@year, :account_id, Arel.star.count)
.to_sql
end
def beginning_of_year
Mastodon::Snowflake.id_at(DateTime.new(@year).beginning_of_year, with_random: false)
end
def end_of_year
Mastodon::Snowflake.id_at(DateTime.new(@year).end_of_year, with_random: false)
end
end
end

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
Fabricator :annual_report_statuses_per_account_count, from: 'AnnualReport::StatusesPerAccountCount' do
year { Time.zone.now.year }
account_id { Fabricate(:account).id }
statuses_count { 123 }
end

View File

@ -7,13 +7,10 @@ RSpec.describe AnnualReport::Percentiles do
subject { described_class.new(account, year) }
let(:year) { Time.zone.now.year }
let(:account) { Fabricate :account }
context 'with an inactive account' do
let(:account) { Fabricate :account }
context 'with no status data' do
it 'builds a report for an account' do
described_class.prepare(year)
expect(subject.generate)
.to include(
percentiles: include(
@ -23,17 +20,16 @@ RSpec.describe AnnualReport::Percentiles do
end
end
context 'with an active account' do
let(:account) { Fabricate :account }
context 'with status count data' do
before do
Fabricate.times 2, :status # Others as `account`
# Simulate scenario where other accounts have each made one status
Fabricate.times 2, :annual_report_statuses_per_account_count, statuses_count: 1
Fabricate.times 2, :status, account: account
Fabricate :annual_report_statuses_per_account_count, account_id: account.id, statuses_count: 2
end
it 'builds a report for an account' do
described_class.prepare(year)
expect(subject.generate)
.to include(
percentiles: include(

View File

@ -0,0 +1,36 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnnualReport::StatusesPerAccountCount do
describe '.refresh' do
subject { described_class.refresh(year) }
let(:year) { Time.zone.now.year }
context 'with an inactive account' do
let(:account) { Fabricate :account }
it 'does not build a status count record' do
expect { subject }
.to not_change(described_class, :count).from(0)
end
end
context 'with an active account' do
let(:account) { Fabricate :account }
before do
Fabricate :status
Fabricate.times 2, :status, account: account
end
it 'builds a status count record' do
expect { subject }
.to change(described_class, :count).by(2)
expect(described_class.where(account_id: account).first)
.to have_attributes(statuses_count: 2)
end
end
end
end