From a28863bf955c90b06632b12cd7302a5481ded351 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Sun, 30 Apr 2017 21:49:24 +0900 Subject: [PATCH] Revert "Use PostgreSQL inheritance for blocks and mutes (#2520)" (#2634) This reverts commit 7cd8e61b5ae29feb73848bdf5a31e4a1cd1646f1. --- app/models/account.rb | 4 ++-- .../20180428000000_create_block_mutes.rb | 19 ------------------- db/schema.rb | 14 +------------- spec/lib/atom_serializer_spec.rb | 4 ++-- spec/models/account_spec.rb | 6 +++--- spec/models/status_spec.rb | 6 +++--- streaming/index.js | 2 +- 7 files changed, 12 insertions(+), 43 deletions(-) delete mode 100644 db/migrate/20180428000000_create_block_mutes.rb diff --git a/app/models/account.rb b/app/models/account.rb index 89710b66cd..19f8ca365a 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -87,11 +87,11 @@ class Account < ApplicationRecord end def block!(other_account) - block_relationships.where(target_account: other_account).first_or_create!(target_account: other_account, block: true) + block_relationships.where(target_account: other_account).first_or_create!(target_account: other_account) end def mute!(other_account) - mute_relationships.where(target_account: other_account).first_or_create!(target_account: other_account, block: false) + mute_relationships.where(target_account: other_account).first_or_create!(target_account: other_account) end def unfollow!(other_account) diff --git a/db/migrate/20180428000000_create_block_mutes.rb b/db/migrate/20180428000000_create_block_mutes.rb deleted file mode 100644 index 149c91a4d2..0000000000 --- a/db/migrate/20180428000000_create_block_mutes.rb +++ /dev/null @@ -1,19 +0,0 @@ -class CreateBlockMutes < ActiveRecord::Migration[5.0] - def change - create_table "block_mutes", force: :casecade do |t| - t.integer "account_id", null: false - t.integer "target_account_id", null: false - t.boolean "block", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - add_column :blocks, :block, :boolean, null: false - execute "ALTER TABLE blocks ADD CONSTRAINT check_mutes_on_block CHECK(block = TRUE), INHERIT block_mutes" - Block.update_all block: true - - add_column :mutes, :block, :boolean, null: false - execute "ALTER TABLE mutes ADD CONSTRAINT check_mutes_on_block CHECK(block = FALSE), INHERIT block_mutes" - Mute.update_all block: false - end -end diff --git a/db/schema.rb b/db/schema.rb index ea948c429f..66326f2e20 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.define(version: 20180428000000) do +ActiveRecord::Schema.define(version: 20170425202925) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -54,23 +54,13 @@ ActiveRecord::Schema.define(version: 20180428000000) do t.index ["username", "domain"], name: "index_accounts_on_username_and_domain", unique: true, using: :btree end - create_table "block_mutes", force: :cascade, id: false do |t| - t.integer "account_id", null: false - t.integer "target_account_id", null: false - t.boolean "block", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - create_table "blocks", force: :cascade do |t| t.integer "account_id", null: false t.integer "target_account_id", null: false - t.boolean "block", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["account_id", "target_account_id"], name: "index_blocks_on_account_id_and_target_account_id", unique: true, using: :btree end - execute "ALTER TABLE blocks ADD CONSTRAINT check_blocks_on_block CHECK(block = TRUE), INHERIT block_mutes" create_table "domain_blocks", force: :cascade do |t| t.string "domain", default: "", null: false @@ -147,12 +137,10 @@ ActiveRecord::Schema.define(version: 20180428000000) do create_table "mutes", force: :cascade do |t| t.integer "account_id", null: false t.integer "target_account_id", null: false - t.boolean "block", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["account_id", "target_account_id"], name: "index_mutes_on_account_id_and_target_account_id", unique: true, using: :btree end - execute "ALTER TABLE mutes ADD CONSTRAINT check_mutes_on_block CHECK(block = FALSE), INHERIT block_mutes" create_table "notifications", force: :cascade do |t| t.integer "account_id" diff --git a/spec/lib/atom_serializer_spec.rb b/spec/lib/atom_serializer_spec.rb index 345285a7a7..cfca82a284 100644 --- a/spec/lib/atom_serializer_spec.rb +++ b/spec/lib/atom_serializer_spec.rb @@ -152,7 +152,7 @@ RSpec.describe AtomSerializer do describe '#block_salmon' do let(:xml) do - block = Fabricate(:block, account: author, target_account: receiver, block: true) + block = Fabricate(:block, account: author, target_account: receiver) xml = AtomSerializer.render(AtomSerializer.new.block_salmon(block)) block.destroy xml @@ -171,7 +171,7 @@ RSpec.describe AtomSerializer do describe '#unblock_salmon' do let(:xml) do - block = Fabricate(:block, account: author, target_account: receiver, block: true) + block = Fabricate(:block, account: author, target_account: receiver) block.destroy xml = AtomSerializer.render(AtomSerializer.new.unblock_salmon(block)) author.block!(receiver) diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index b4481aaed9..157db633a0 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -193,9 +193,9 @@ RSpec.describe Account, type: :model do describe '#excluded_from_timeline_account_ids' do it 'includes account ids of blockings, blocked_bys and mutes' do account = Fabricate(:account) - block = Fabricate(:block, account: account, block: true) - mute = Fabricate(:mute, account: account, block: false) - block_by = Fabricate(:block, target_account: account, block: true) + block = Fabricate(:block, account: account) + mute = Fabricate(:mute, account: account) + block_by = Fabricate(:block, target_account: account) results = account.excluded_from_timeline_account_ids expect(results.size).to eq 3 diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index 956b9b882d..c553b052e7 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -226,7 +226,7 @@ RSpec.describe Status, type: :model do it 'excludes statuses from accounts blocked by the account' do blocked = Fabricate(:account) - Fabricate(:block, account: @account, target_account: blocked, block: true) + Fabricate(:block, account: @account, target_account: blocked) blocked_status = Fabricate(:status, account: blocked) results = Status.as_public_timeline(@account) @@ -235,7 +235,7 @@ RSpec.describe Status, type: :model do it 'excludes statuses from accounts who have blocked the account' do blocked = Fabricate(:account) - Fabricate(:block, account: blocked, target_account: @account, block: true) + Fabricate(:block, account: blocked, target_account: @account) blocked_status = Fabricate(:status, account: blocked) results = Status.as_public_timeline(@account) @@ -244,7 +244,7 @@ RSpec.describe Status, type: :model do it 'excludes statuses from accounts muted by the account' do muted = Fabricate(:account) - Fabricate(:mute, account: @account, target_account: muted, block: false) + Fabricate(:mute, account: @account, target_account: muted) muted_status = Fabricate(:status, account: muted) results = Status.as_public_timeline(@account) diff --git a/streaming/index.js b/streaming/index.js index da8066ff33..3be8440372 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -188,7 +188,7 @@ if (cluster.isMaster) { const unpackedPayload = JSON.parse(payload) const targetAccountIds = [unpackedPayload.account.id].concat(unpackedPayload.mentions.map(item => item.id)).concat(unpackedPayload.reblog ? [unpackedPayload.reblog.account.id] : []) - client.query(`SELECT target_account_id FROM block_mutes WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 1)})`, [req.accountId].concat(targetAccountIds), (err, result) => { + client.query(`SELECT target_account_id FROM blocks WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 1)}) UNION SELECT target_account_id FROM mutes WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 1)})`, [req.accountId].concat(targetAccountIds), (err, result) => { done() if (err) {