mastodon.zunda.ninja is one of the many independent Mastodon servers you can use to participate in the fediverse.
Zundon is a single user instance as home of @zundan as well as a test bed for changes of the code.

Administered by:

Server stats:

1
active users

zunda

WebUIのメニューから削除すると
method=DELETE path=/api/v1/statuses/:id format=html controller=Api::V1::StatusesController action=destroy
でちゃんと消えてるわね

$ heroku run bash
~ $ rails c
> current_account = Account.find_by(username: 'zunda')
> params = {id: 109290136626742219}
> Api::V1::StatusesController.new.destroy
/app/vendor/bundle/ruby/3.1.0/gems/doorkeeper-5.6.0/lib/doorkeeper/oauth/token.rb:35:in `from_bearer_authorization': undefined method `authorization' for nil:NilClass (NoMethodError)

header = request.authorization
^^^^^^^^^^^^^^

おおうRailsむずかしいなw

コントローラから余計(?)な行を取り除いてこれでデータベースの行を消せることは確認した。次はIDの取得わね。

$ heroku run bash
~ $ rails c
> def destroy_status(account_id, status_id)
status = Status.where(account: Account.find(account_id)).find(status_id)
status.discard_with_reblogs
StatusPin.find_by(status: status)&.destroy
status.account.statuses_count = status.account.statuses_count - 1
RemovalWorker.perform_async(status.id, { 'redraft' => true })
end
> destroy_status(107475339473892866, 109406171267058080)
=> "634844905c40485e1b155920"

アカウント関係なく古いステータスだけ取得すればいいんだから

> Status.where(:created_at => ..Time.now - 2.years)

みたいのでいいんだ。

消してみた。うりゃ!ってデバッグログがいっぱい出るので戻り値は消したポストの数みたいのにしておけばよかったな。

> def destroy_status(days, dry_run = true)
Status.where(:created_at => .. Time.now - days*24*3600).each do |s|
puts s.id
unless dry_run
s.discard_with_reblogs
StatusPin.find_by(status: s)&.destroy
s.account.statuses_count = s.account.statuses_count - 1
RemovalWorker.perform_async(s.id, { 'redraft' => true })
end
end
nil
end
> destroy_status(180, false)

行数の再計数はすぐには起きないので結果は明日のお楽しみ。

酔っ払いなのですぐ確認した

$ heroku pg:info
=== DATABASE_URL
Plan: Mini
Status: Available
Connections: 2/20
PG Version: 13.9
Created: 2021-11-23 02:52 UTC
Data Size: 18.0 MB/1.00 GB (In compliance)
Tables: 93
Rows: 7893/10000 (In compliance, close to row limit)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-crystalline-90176

8052行から200行弱減ったね。それだけかーw