From dfa43707eb88276b8268e49c7853d226006bf140 Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 22 Mar 2024 16:44:31 +0100 Subject: [PATCH] Change `AccountRelationshipSeveranceEvent` model to store lost followers and following counts separately (#29714) --- .../components/relationships_severance_event.jsx | 2 +- app/models/account_relationship_severance_event.rb | 10 ++++++++-- .../account_relationship_severance_event_serializer.rb | 2 +- app/views/severed_relationships/index.html.haml | 4 ++-- ..._counts_to_account_relationship_severance_events.rb | 8 ++++++++ ...count_from_account_relationship_severance_events.rb | 7 +++++++ db/schema.rb | 5 +++-- 7 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20240322125607_add_followers_and_following_counts_to_account_relationship_severance_events.rb create mode 100644 db/post_migrate/20240322130318_remove_relationships_count_from_account_relationship_severance_events.rb diff --git a/app/javascript/mastodon/features/notifications/components/relationships_severance_event.jsx b/app/javascript/mastodon/features/notifications/components/relationships_severance_event.jsx index 12bc5f130d0..23d0d2eecf3 100644 --- a/app/javascript/mastodon/features/notifications/components/relationships_severance_event.jsx +++ b/app/javascript/mastodon/features/notifications/components/relationships_severance_event.jsx @@ -35,7 +35,7 @@ const RelationshipsSeveranceEvent = ({ event, hidden }) => { )}
diff --git a/app/models/account_relationship_severance_event.rb b/app/models/account_relationship_severance_event.rb index 697b06b74b4..c1269fad6d9 100644 --- a/app/models/account_relationship_severance_event.rb +++ b/app/models/account_relationship_severance_event.rb @@ -8,11 +8,16 @@ # id :bigint(8) not null, primary key # account_id :bigint(8) not null # relationship_severance_event_id :bigint(8) not null -# relationships_count :integer default(0), not null # created_at :datetime not null # updated_at :datetime not null +# followers_count :integer default(0), not null +# following_count :integer default(0), not null # class AccountRelationshipSeveranceEvent < ApplicationRecord + self.ignored_columns += %w( + relationships_count + ) + belongs_to :account belongs_to :relationship_severance_event @@ -30,6 +35,7 @@ class AccountRelationshipSeveranceEvent < ApplicationRecord private def set_relationships_count! - self.relationships_count = severed_relationships.about_local_account(account).count + self.followers_count = severed_relationships.about_local_account(account).passive.count + self.following_count = severed_relationships.about_local_account(account).active.count end end diff --git a/app/serializers/rest/account_relationship_severance_event_serializer.rb b/app/serializers/rest/account_relationship_severance_event_serializer.rb index 2578e3a20fc..751bc103c2c 100644 --- a/app/serializers/rest/account_relationship_severance_event_serializer.rb +++ b/app/serializers/rest/account_relationship_severance_event_serializer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class REST::AccountRelationshipSeveranceEventSerializer < ActiveModel::Serializer - attributes :id, :type, :purged, :target_name, :created_at + attributes :id, :type, :purged, :target_name, :followers_count, :following_count, :created_at def id object.id.to_s diff --git a/app/views/severed_relationships/index.html.haml b/app/views/severed_relationships/index.html.haml index 75296d90aaf..7c599e9c0e7 100644 --- a/app/views/severed_relationships/index.html.haml +++ b/app/views/severed_relationships/index.html.haml @@ -21,13 +21,13 @@ %td{ rowspan: 2 }= t('severed_relationships.purged') - else %td - - count = event.severed_relationships.active.about_local_account(current_account).count + - count = event.following_count - if count.zero? = t('generic.none') - else = table_link_to 'download', t('severed_relationships.download', count: count), following_severed_relationship_path(event, format: :csv) %td - - count = event.severed_relationships.passive.about_local_account(current_account).count + - count = event.followers_count - if count.zero? = t('generic.none') - else diff --git a/db/migrate/20240322125607_add_followers_and_following_counts_to_account_relationship_severance_events.rb b/db/migrate/20240322125607_add_followers_and_following_counts_to_account_relationship_severance_events.rb new file mode 100644 index 00000000000..ab5752b7a5a --- /dev/null +++ b/db/migrate/20240322125607_add_followers_and_following_counts_to_account_relationship_severance_events.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddFollowersAndFollowingCountsToAccountRelationshipSeveranceEvents < ActiveRecord::Migration[7.1] + def change + add_column :account_relationship_severance_events, :followers_count, :integer, default: 0, null: false + add_column :account_relationship_severance_events, :following_count, :integer, default: 0, null: false + end +end diff --git a/db/post_migrate/20240322130318_remove_relationships_count_from_account_relationship_severance_events.rb b/db/post_migrate/20240322130318_remove_relationships_count_from_account_relationship_severance_events.rb new file mode 100644 index 00000000000..76f2d325fe5 --- /dev/null +++ b/db/post_migrate/20240322130318_remove_relationships_count_from_account_relationship_severance_events.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class RemoveRelationshipsCountFromAccountRelationshipSeveranceEvents < ActiveRecord::Migration[7.1] + def change + safety_assured { remove_column :account_relationship_severance_events, :relationships_count, :integer, default: 0, null: false } + end +end diff --git a/db/schema.rb b/db/schema.rb index 34563191585..dcf16a7ed93 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_03_21_160706) do +ActiveRecord::Schema[7.1].define(version: 2024_03_22_130318) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -93,9 +93,10 @@ ActiveRecord::Schema[7.1].define(version: 2024_03_21_160706) do create_table "account_relationship_severance_events", force: :cascade do |t| t.bigint "account_id", null: false t.bigint "relationship_severance_event_id", null: false - t.integer "relationships_count", default: 0, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "followers_count", default: 0, null: false + t.integer "following_count", default: 0, null: false t.index ["account_id", "relationship_severance_event_id"], name: "idx_on_account_id_relationship_severance_event_id_7bd82bf20e", unique: true t.index ["account_id"], name: "index_account_relationship_severance_events_on_account_id" t.index ["relationship_severance_event_id"], name: "idx_on_relationship_severance_event_id_403f53e707"