Switch to static URIs, new URI format in both protocols for new statuses (#4815)

* Decouple Status#local? from uri being nil

* Replace on-the-fly URI generation with stored URIs

- Generate URI in after_save hook for local statuses
- Use static value in TagManager when available, fallback to tag format
- Make TagManager use ActivityPub::TagManager to understand new format
- Adjust tests

* Use other heuristic for locality of old statuses, do not perform long query

* Exclude tombstone stream entries from Atom feed

* Prevent nil statuses from landing in Pubsubhubbub::DistributionWorker

* Fix URI not being saved (#4818)

* Add more specs for Status

* Save generated uri immediately

and also fix method order to minimize diff.

* Fix alternate HTML URL in Atom

* Fix tests

* Remove not-null constraint from statuses migration to speed it up
This commit is contained in:
Eugen Rochko
2017-09-06 19:01:28 +02:00
committed by GitHub
parent 13ffa3c59e
commit e7adbf572a
15 changed files with 84 additions and 46 deletions

View File

@ -22,6 +22,7 @@
# reblogs_count :integer default(0), not null
# language :string
# conversation_id :integer
# local :boolean default(FALSE)
#
class Status < ApplicationRecord
@ -84,7 +85,7 @@ class Status < ApplicationRecord
end
def local?
uri.nil?
attributes['local'] || uri.nil?
end
def reblog?
@ -131,11 +132,14 @@ class Status < ApplicationRecord
!sensitive? && media_attachments.any?
end
after_create :store_uri, if: :local?
before_validation :prepare_contents, if: :local?
before_validation :set_reblog
before_validation :set_visibility
before_validation :set_conversation
before_validation :set_sensitivity
before_validation :set_local
class << self
def not_in_filtered_languages(account)
@ -253,6 +257,10 @@ class Status < ApplicationRecord
private
def store_uri
update_attribute(:uri, ActivityPub::TagManager.instance.uri_for(self)) if uri.nil?
end
def prepare_contents
text&.strip!
spoiler_text&.strip!
@ -292,4 +300,8 @@ class Status < ApplicationRecord
thread.account_id
end
end
def set_local
self.local = account.local?
end
end