aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-07-28 17:30:12 +0200
committerGitHub <noreply@github.com>2019-07-28 17:30:12 +0200
commit75f7f9930eb2a6f5c4041ec44fe0aa795c9ec449 (patch)
tree446b7fa050fa9e4c624a46eef874c5bd4441137e
parentcfb2ed78231758a79af038a964ab7f7b7b35274e (diff)
downloadmastodon-75f7f9930eb2a6f5c4041ec44fe0aa795c9ec449.tar
mastodon-75f7f9930eb2a6f5c4041ec44fe0aa795c9ec449.tar.gz
mastodon-75f7f9930eb2a6f5c4041ec44fe0aa795c9ec449.tar.bz2
mastodon-75f7f9930eb2a6f5c4041ec44fe0aa795c9ec449.zip
Remove conversation URI (#11423)
It is not part of ActivityPub and will free up a lot of space
-rw-r--r--app/lib/activitypub/activity/create.rb11
-rw-r--r--app/models/conversation.rb7
-rw-r--r--app/serializers/activitypub/note_serializer.rb15
-rw-r--r--db/post_migrate/20190519130537_remove_boosts_widening_audience.rb2
-rw-r--r--db/post_migrate/20190728084117_remove_uri_from_conversations.rb12
-rw-r--r--db/schema.rb4
-rw-r--r--spec/models/conversation_spec.rb8
7 files changed, 17 insertions, 42 deletions
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb
index 000b77df5..eb7b09e44 100644
--- a/app/lib/activitypub/activity/create.rb
+++ b/app/lib/activitypub/activity/create.rb
@@ -67,7 +67,6 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
sensitive: @object['sensitive'] || false,
visibility: visibility_from_audience,
thread: replied_to_status,
- conversation: conversation_from_uri(@object['conversation']),
media_attachment_ids: process_attachments.take(4).map(&:id),
poll: process_poll,
}
@@ -262,16 +261,6 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
ActivityPub::FetchRepliesWorker.perform_async(status.id, uri) unless uri.nil?
end
- def conversation_from_uri(uri)
- return nil if uri.nil?
- return Conversation.find_by(id: OStatus::TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')) if OStatus::TagManager.instance.local_id?(uri)
- begin
- Conversation.find_or_create_by!(uri: uri)
- rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
- retry
- end
- end
-
def visibility_from_audience
if equals_or_includes?(@object['to'], ActivityPub::TagManager::COLLECTIONS[:public])
:public
diff --git a/app/models/conversation.rb b/app/models/conversation.rb
index 4dfaea889..37d233f32 100644
--- a/app/models/conversation.rb
+++ b/app/models/conversation.rb
@@ -4,17 +4,10 @@
# Table name: conversations
#
# id :bigint(8) not null, primary key
-# uri :string
# created_at :datetime not null
# updated_at :datetime not null
#
class Conversation < ApplicationRecord
- validates :uri, uniqueness: true, if: :uri?
-
has_many :statuses
-
- def local?
- uri.nil?
- end
end
diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb
index 67f596e78..88b50b3ea 100644
--- a/app/serializers/activitypub/note_serializer.rb
+++ b/app/serializers/activitypub/note_serializer.rb
@@ -1,14 +1,13 @@
# frozen_string_literal: true
class ActivityPub::NoteSerializer < ActivityPub::Serializer
- context_extensions :atom_uri, :conversation, :sensitive,
+ context_extensions :atom_uri, :sensitive,
:hashtag, :emoji, :focal_point, :blurhash
attributes :id, :type, :summary,
:in_reply_to, :published, :url,
:attributed_to, :to, :cc, :sensitive,
- :atom_uri, :in_reply_to_atom_uri,
- :conversation
+ :atom_uri, :in_reply_to_atom_uri
attribute :content
attribute :content_map, if: :language?
@@ -110,16 +109,6 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
OStatus::TagManager.instance.uri_for(object.thread)
end
- def conversation
- return if object.conversation.nil?
-
- if object.conversation.uri?
- object.conversation.uri
- else
- OStatus::TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation')
- end
- end
-
def local?
object.account.local?
end
diff --git a/db/post_migrate/20190519130537_remove_boosts_widening_audience.rb b/db/post_migrate/20190519130537_remove_boosts_widening_audience.rb
index d2d924239..b89efd989 100644
--- a/db/post_migrate/20190519130537_remove_boosts_widening_audience.rb
+++ b/db/post_migrate/20190519130537_remove_boosts_widening_audience.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class RemoveBoostsWideningAudience < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
diff --git a/db/post_migrate/20190728084117_remove_uri_from_conversations.rb b/db/post_migrate/20190728084117_remove_uri_from_conversations.rb
new file mode 100644
index 000000000..b2b157ef7
--- /dev/null
+++ b/db/post_migrate/20190728084117_remove_uri_from_conversations.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+class RemoveUriFromConversations < ActiveRecord::Migration[5.2]
+ def up
+ safety_assured { remove_column :conversations, :uri, :string }
+ end
+
+ def down
+ add_column :conversations, :uri, :string
+ add_index :conversations, :uri, unique: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 1847305c7..a722bad36 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: 2019_07_26_175042) do
+ActiveRecord::Schema.define(version: 2019_07_28_084117) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -203,10 +203,8 @@ ActiveRecord::Schema.define(version: 2019_07_26_175042) do
end
create_table "conversations", force: :cascade do |t|
- t.string "uri"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.index ["uri"], name: "index_conversations_on_uri", unique: true
end
create_table "custom_emoji_categories", force: :cascade do |t|
diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb
index 8b5e4fdaf..b91d36169 100644
--- a/spec/models/conversation_spec.rb
+++ b/spec/models/conversation_spec.rb
@@ -1,13 +1,5 @@
require 'rails_helper'
RSpec.describe Conversation, type: :model do
- describe '#local?' do
- it 'returns true when URI is nil' do
- expect(Fabricate(:conversation).local?).to be true
- end
- it 'returns false when URI is not nil' do
- expect(Fabricate(:conversation, uri: 'abc').local?).to be false
- end
- end
end