Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add post-deployment migration script to delete public-boosts-of-private boosts #10783

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions db/post_migrate/20190519130537_remove_boosts_widening_audience.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class RemoveBoostsWideningAudience < ActiveRecord::Migration[5.2]
disable_ddl_transaction!

def up
public_boosts = Status.find_by_sql(<<-SQL)
SELECT boost.id
FROM statuses AS boost
LEFT JOIN statuses AS boosted ON boost.reblog_of_id = boosted.id
WHERE
boost.id > 101746055577600000
AND (boost.local = TRUE OR boost.uri IS NULL)
AND boost.visibility IN (0, 1)
AND boost.reblog_of_id IS NOT NULL
AND boosted.visibility = 2
SQL

RemovalWorker.push_bulk(public_boosts.pluck(:id))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_by_sql already loads full models, it does not return a relation, so pluck is equivalent to map(&:id) here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, ok, parts of the Mastodon code do that though. Is there something lighter we could do? We only need the id.

end

def down
raise ActiveRecord::IrreversibleMigration
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_05_11_152737) do
ActiveRecord::Schema.define(version: 2019_05_19_130537) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down