Dedicated `network` DB column for marking whether a roar is a part of the local network; rewrite posts from `FORCE_*` domains at create time instead of dynamically.

staging
multiple creatures 2019-04-17 00:15:10 -05:00
parent cdacbb3c4c
commit 3bfa72cbce
4 changed files with 20 additions and 14 deletions

View File

@ -67,6 +67,8 @@ class Account < ApplicationRecord
MAX_NOTE_LENGTH = (ENV['MAX_BIO_CHARS'] || 500).to_i
MAX_FIELDS = (ENV['MAX_PROFILE_FIELDS'] || 4).to_i
LOCAL_DOMAINS = ENV.fetch('LOCAL_DOMAINS', '').chomp.split(/\.?\s+/).freeze
enum protocol: [:ostatus, :activitypub]
validates :username, presence: true
@ -127,6 +129,10 @@ class Account < ApplicationRecord
domain.nil?
end
def network?
local? || domain.in?(LOCAL_DOMAINS)
end
def moved?
moved_to_account_id.present?
end

View File

@ -27,6 +27,7 @@
# tsv :tsvector
# curated :boolean
# sharekey :string
# network :boolean
#
class Status < ApplicationRecord
@ -38,7 +39,6 @@ class Status < ApplicationRecord
include StatusThreadingConcern
LOCAL_DOMAINS = ENV.fetch('LOCAL_DOMAINS', '').chomp.split(/\.?\s+/).freeze
LOCAL_URIS = LOCAL_DOMAINS.map { |domain| "https://#{domain}/%" }.freeze
FORCE_SENSITIVE = ENV.fetch('FORCE_SENSITIVE', '').chomp.split(/\.?\s+/).freeze
FORCE_UNLISTED = ENV.fetch('FORCE_UNLISTED', '').chomp.split(/\.?\s+/).freeze
@ -91,7 +91,7 @@ class Status < ApplicationRecord
scope :recent, -> { reorder(id: :desc) }
scope :remote, -> { where(local: false).or(where.not(uri: nil)) }
scope :local, -> { where(local: true).or(where(uri: nil)) }
scope :network, -> { where(local: true).or(where(uri: nil)).or(where('statuses.uri LIKE ANY (array[?])', LOCAL_URIS)) }
scope :network, -> { where(network: true) }
scope :curated, -> { where(curated: true) }
scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') }
@ -175,7 +175,7 @@ class Status < ApplicationRecord
end
def network?
attributes['local'] || uri.nil? || account.domain.in?(LOCAL_DOMAINS)
attributes['network'] || local? || account.domain.in?(LOCAL_DOMAINS)
end
def relayed?
@ -298,8 +298,6 @@ class Status < ApplicationRecord
after_create :set_poll_id
after_create :process_bangtags, if: :local?
after_find :limit_domain_visibility
class << self
def search_for(term, limit = 66, account = nil)
pattern = sanitize_sql_like(term)
@ -462,7 +460,7 @@ class Status < ApplicationRecord
private
def timeline_scope(local_only = false)
starting_scope = local_only ? Status.local : Status
starting_scope = local_only ? Status.network : Status
starting_scope = starting_scope.with_public_visibility
if Setting.show_reblogs_in_public_timelines
starting_scope
@ -472,7 +470,7 @@ class Status < ApplicationRecord
end
def browsable_timeline_scope(local_only = false)
starting_scope = local_only ? Status.local : Status
starting_scope = local_only ? Status.network : Status
starting_scope
.public_browsable
.without_reblogs
@ -547,16 +545,11 @@ class Status < ApplicationRecord
def set_visibility
self.visibility = reblog.visibility if reblog? && visibility.nil?
self.visibility = (account.locked? ? :private : :public) if visibility.nil?
self.visibility = :unlisted if visibility == :public && account.domain.in?(FORCE_UNLISTED)
self.sensitive = true if account.domain.in?(FORCE_SENSITIVE)
self.sensitive = false if sensitive.nil?
end
def limit_domain_visibility
return unless has_attribute?(:uri) && !uri.nil?
domain = Addressable::URI.parse(uri).host
self.sensitive = true if domain.in?(FORCE_SENSITIVE)
self.visibility = :unlisted if public_visibility? && domain.in?(FORCE_UNLISTED)
end
def set_locality
if account.domain.nil? && !attribute_changed?(:local_only)
self.local_only = marked_local_only?
@ -939,6 +932,7 @@ class Status < ApplicationRecord
def set_local
self.local = account.local?
self.network = account.network?
end
def update_statistics

View File

@ -0,0 +1,5 @@
class AddNetworkToStatus < ActiveRecord::Migration[5.2]
def change
add_column :statuses, :network, :boolean
end
end

View File

@ -642,6 +642,7 @@ ActiveRecord::Schema.define(version: 2019_05_19_130537) do
t.tsvector "tsv"
t.boolean "curated"
t.string "sharekey"
t.boolean "network"
t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20180106", order: { id: :desc }
t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id"
t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id"