Remove: #611 グループシステム関係のカラムを複数削除 (#618)

This commit is contained in:
KMY(雪あすか) 2024-02-27 13:08:30 +09:00 committed by GitHub
parent 0767212284
commit aec832e257
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 29 additions and 97 deletions

View file

@ -20,8 +20,8 @@ class Settings::ProfilesController < Settings::BaseController
private
def account_params
# params.require(:account).permit(:display_name, :note, :bio_markdown, :avatar, :header, :locked, :my_actor_type, :searchability, :dissubscribable, :group_allow_private_message, :discoverable, :discoverable_local, :hide_collections, fields_attributes: [:name, :value])
params.require(:account).permit(:display_name, :note, :bio_markdown, :avatar, :header, :bot, :my_actor_type, :group_allow_private_message, :dissubscribable, fields_attributes: [:name, :value])
# params.require(:account).permit(:display_name, :note, :bio_markdown, :avatar, :header, :locked, :my_actor_type, :searchability, :dissubscribable, :discoverable, :discoverable_local, :hide_collections, fields_attributes: [:name, :value])
params.require(:account).permit(:display_name, :note, :bio_markdown, :avatar, :header, :bot, :my_actor_type, :dissubscribable, fields_attributes: [:name, :value])
end
def set_account

View file

@ -50,7 +50,6 @@
# trendable :boolean
# reviewed_at :datetime
# requested_review_at :datetime
# group_allow_private_message :boolean
# searchability :integer default("direct"), not null
# settings :jsonb
# indexable :boolean default(FALSE), not null

View file

@ -4,15 +4,14 @@
#
# Table name: account_stats
#
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# statuses_count :bigint(8) default(0), not null
# following_count :bigint(8) default(0), not null
# followers_count :bigint(8) default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
# last_status_at :datetime
# group_activitypub_count :integer
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# statuses_count :bigint(8) default(0), not null
# following_count :bigint(8) default(0), not null
# followers_count :bigint(8) default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
# last_status_at :datetime
#
class AccountStat < ApplicationRecord
@ -34,8 +33,4 @@ class AccountStat < ApplicationRecord
def statuses_count
[attributes['statuses_count'], 0].max
end
def group_activitypub_count
[attributes['group_activitypub_count'] || 0, 0].max
end
end

View file

@ -16,8 +16,6 @@ module Account::Counters
:following_count=,
:followers_count,
:followers_count=,
:group_activitypub_count,
:group_activitypub_count=,
:last_status_at,
to: :account_stat

View file

@ -29,8 +29,8 @@
# status_poll_state :integer default("optional"), not null
# status_quote_state :integer default("optional"), not null
# status_reply_state :integer default("optional"), not null
# status_mention_state :integer default(0), not null
# status_reference_state :integer default(0), not null
# status_mention_state :integer default("optional"), not null
# status_reference_state :integer default("optional"), not null
# status_tag_threshold :integer default(-1), not null
# status_media_threshold :integer default(-1), not null
# status_poll_threshold :integer default(-1), not null

View file

@ -1,88 +1,19 @@
# frozen_string_literal: true
class GroupReblogService < BaseService
include RoutingHelper
ACTIVITYPUB_CONTINUOUS_SIZE = 30
def call(status)
return nil if status.account.group?
visibility = status.visibility.to_sym
return nil unless %i(public public_unlisted unlisted login private direct).include?(visibility)
return nil unless %i(public public_unlisted unlisted login).include?(visibility)
accounts = status.mentions.map(&:account) | status.active_mentions.map(&:account)
transcription = %i(private direct).include?(visibility)
accounts.each do |account|
status.mentions.map(&:account).each do |account|
next unless account.local?
next unless status.account.following?(account)
next unless account.group?
next if account.id == status.account_id
next if transcription && !account.group_allow_private_message
if status.account.activitypub? && ACTIVITYPUB_CONTINUOUS_SIZE.positive?
next if account.group_activitypub_count >= ACTIVITYPUB_CONTINUOUS_SIZE
account.group_activitypub_count = account.group_activitypub_count + 1
account.save!
elsif account.group_activitypub_count.positive?
account.group_activitypub_count = 0
account.save!
end
ReblogService.new.call(account, status, { visibility: status.visibility }) unless transcription
next unless transcription
username = status.account.local? ? status.account.username : "#{status.account.username}@#{status.account.domain}"
media_attachments = status.media_attachments.map do |media|
media.needs_redownload? ? media_proxy_url(media.id, :original) : full_asset_url(media.file.url(:original))
MediaAttachment.create(
account: account,
remote_url: media_url(media),
thumbnail_remote_url: media_preview_url(media)
).tap do |attachment|
attachment.download_file!
attachment.save
end
end
text = status.account.local? ? status.text : strip_tags(status.text.gsub('<br>', "\n").gsub(%r{<br />}, "\n").gsub(%r{</p>}, "\n\n").strip)
PostStatusService.new.call(
account,
text: "Private message by @#{username}\n\\-\\-\\-\\-\n#{text}",
thread: status.thread,
media_ids: media_attachments.map(&:id),
sensitive: status.sensitive,
spoiler_text: status.spoiler_text,
visibility: :private,
language: status.language,
poll: status.poll,
with_rate_limit: true
)
end
end
def media_url(media)
if media.not_processed?
nil
elsif media.needs_redownload?
media_proxy_url(media.id, :original)
else
full_asset_url(media.file.url(:original))
end
end
def media_preview_url(media)
if media.needs_redownload?
media_proxy_url(media.id, :small)
elsif media.thumbnail.present?
full_asset_url(media.thumbnail.url(:original))
elsif media.file.styles.key?(:small)
full_asset_url(media.file.url(:small))
ReblogService.new.call(account, status, { visibility: status.visibility })
end
end
end

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
class RemoveGroupAttrsFromAccounts < ActiveRecord::Migration[7.1]
def change
safety_assured do
remove_column :accounts, :group_allow_private_message, :boolean
remove_column :account_stats, :group_activitypub_count, :integer
end
end
end

View file

@ -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_02_18_233621) do
ActiveRecord::Schema[7.1].define(version: 2024_02_27_033337) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -98,7 +98,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_18_233621) do
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.datetime "last_status_at", precision: nil
t.integer "group_activitypub_count"
t.index ["account_id"], name: "index_account_stats_on_account_id", unique: true
t.index ["last_status_at", "account_id"], name: "index_account_stats_on_last_status_at_and_account_id", order: { last_status_at: "DESC NULLS LAST" }
end
@ -189,7 +188,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_18_233621) do
t.boolean "trendable"
t.datetime "reviewed_at", precision: nil
t.datetime "requested_review_at", precision: nil
t.boolean "group_allow_private_message"
t.integer "searchability", default: 2, null: false
t.jsonb "settings"
t.boolean "indexable", default: false, null: false

View file

@ -89,6 +89,7 @@ namespace :dangerous do
20240217093511
20240217230006
20240218233621
20240227033337
)
# Removed: account_groups
target_tables = %w(
@ -115,14 +116,14 @@ namespace :dangerous do
)
target_table_columns = [
# Removed: accounts dissubscribable
%w(accounts group_allow_private_message),
# Removed: accounts group_allow_private_message
# Removed: accounts group_message_following_only
%w(accounts master_settings),
%w(accounts remote_pending),
%w(accounts searchability),
%w(accounts settings),
# Removed: accounts stop_emoji_reaction_streaming
%w(account_stats group_activitypub_count),
# Removed: account_stats group_activitypub_count
%w(account_statuses_cleanup_policies keep_self_emoji),
%w(account_statuses_cleanup_policies min_emojis),
%w(conversations ancestor_status_id),