Merge tag 'v2.6.5' into instance_only_statuses

This commit is contained in:
Renato "Lond" Cerqueira
2018-12-07 15:27:23 +01:00
298 changed files with 2754 additions and 1673 deletions

View File

@ -49,7 +49,7 @@
#
class Account < ApplicationRecord
USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.]+[a-z0-9_]+)?/i
USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
include AccountAvatar

View File

@ -58,6 +58,9 @@ class AccountConversation < ApplicationRecord
def add_status(recipient, status)
conversation = find_or_initialize_by(account: recipient, conversation_id: status.conversation_id, participant_account_ids: participants_from_status(recipient, status))
return conversation if conversation.status_ids.include?(status.id)
conversation.status_ids << status.id
conversation.unread = status.account_id != recipient.id
conversation.save

View File

@ -45,9 +45,9 @@ module AccountInteractions
end
def domain_blocking_map(target_account_ids, account_id)
accounts_map = Account.where(id: target_account_ids).select('id, domain').map { |a| [a.id, a.domain] }.to_h
accounts_map = Account.where(id: target_account_ids).select('id, domain').each_with_object({}) { |a, h| h[a.id] = a.domain }
blocked_domains = domain_blocking_map_by_domain(accounts_map.values.compact, account_id)
accounts_map.map { |id, domain| [id, blocked_domains[domain]] }.to_h
accounts_map.reduce({}) { |h, (id, domain)| h.merge(id => blocked_domains[domain]) }
end
def domain_blocking_map_by_domain(target_domains, account_id)

View File

@ -59,6 +59,7 @@ class MediaAttachment < ApplicationRecord
format: 'mp4',
convert_options: {
output: {
'loglevel' => 'fatal',
'movflags' => 'faststart',
'pix_fmt' => 'yuv420p',
'vf' => 'scale=\'trunc(iw/2)*2:trunc(ih/2)*2\'',
@ -130,6 +131,7 @@ class MediaAttachment < ApplicationRecord
"#{x},#{y}"
end
after_commit :reset_parent_cache, on: :update
before_create :prepare_description, unless: :local?
before_create :set_shortcode
before_post_process :set_type_and_extension
@ -230,4 +232,9 @@ class MediaAttachment < ApplicationRecord
bitrate: movie.bitrate,
}
end
def reset_parent_cache
return if status_id.nil?
Rails.cache.delete("statuses/#{status_id}")
end
end

View File

@ -75,7 +75,7 @@ class Notification < ApplicationRecord
return if account_ids.empty?
accounts = Account.where(id: account_ids).map { |a| [a.id, a] }.to_h
accounts = Account.where(id: account_ids).each_with_object({}) { |a, h| h[a.id] = a }
cached_items.each do |item|
item.from_account = accounts[item.from_account_id]

View File

@ -40,7 +40,7 @@ class Setting < RailsSettings::Base
def all_as_records
vars = thing_scoped
records = vars.map { |r| [r.var, r] }.to_h
records = vars.each_with_object({}) { |r, h| h[r.var] = r }
default_settings.each do |key, default_value|
next if records.key?(key) || default_value.is_a?(Hash)

View File

@ -91,6 +91,7 @@ class Status < ApplicationRecord
:conversation,
:status_stat,
:tags,
:preview_cards,
:stream_entry,
active_mentions: :account,
reblog: [
@ -98,6 +99,7 @@ class Status < ApplicationRecord
:application,
:stream_entry,
:tags,
:preview_cards,
:media_attachments,
:conversation,
:status_stat,
@ -169,6 +171,10 @@ class Status < ApplicationRecord
reblog
end
def preview_card
preview_cards.first
end
def title
if destroyed?
"#{account.acct} deleted status"
@ -242,10 +248,6 @@ class Status < ApplicationRecord
before_validation :set_local
class << self
def cache_ids
left_outer_joins(:status_stat).select('statuses.id, greatest(statuses.updated_at, status_stats.updated_at) AS updated_at')
end
def selectable_visibilities
visibilities.keys - %w(direct limited)
end
@ -316,19 +318,19 @@ class Status < ApplicationRecord
end
def favourites_map(status_ids, account_id)
Favourite.select('status_id').where(status_id: status_ids).where(account_id: account_id).map { |f| [f.status_id, true] }.to_h
Favourite.select('status_id').where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |f, h| h[f.status_id] = true }
end
def reblogs_map(status_ids, account_id)
select('reblog_of_id').where(reblog_of_id: status_ids).where(account_id: account_id).reorder(nil).map { |s| [s.reblog_of_id, true] }.to_h
select('reblog_of_id').where(reblog_of_id: status_ids).where(account_id: account_id).reorder(nil).each_with_object({}) { |s, h| h[s.reblog_of_id] = true }
end
def mutes_map(conversation_ids, account_id)
ConversationMute.select('conversation_id').where(conversation_id: conversation_ids).where(account_id: account_id).map { |m| [m.conversation_id, true] }.to_h
ConversationMute.select('conversation_id').where(conversation_id: conversation_ids).where(account_id: account_id).each_with_object({}) { |m, h| h[m.conversation_id] = true }
end
def pins_map(status_ids, account_id)
StatusPin.select('status_id').where(status_id: status_ids).where(account_id: account_id).map { |p| [p.status_id, true] }.to_h
StatusPin.select('status_id').where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |p, h| h[p.status_id] = true }
end
def reload_stale_associations!(cached_items)
@ -343,7 +345,7 @@ class Status < ApplicationRecord
return if account_ids.empty?
accounts = Account.where(id: account_ids).map { |a| [a.id, a] }.to_h
accounts = Account.where(id: account_ids).each_with_object({}) { |a, h| h[a.id] = a }
cached_items.each do |item|
item.account = accounts[item.account_id]

View File

@ -14,4 +14,12 @@
class StatusStat < ApplicationRecord
belongs_to :status, inverse_of: :status_stat
after_commit :reset_parent_cache
private
def reset_parent_cache
Rails.cache.delete("statuses/#{status_id}")
end
end

View File

@ -18,7 +18,7 @@ class TrendingTags
def get(limit)
key = "#{KEY}:#{Time.now.utc.beginning_of_day.to_i}"
tag_ids = redis.zrevrange(key, 0, limit - 1).map(&:to_i)
tags = Tag.where(id: tag_ids).to_a.map { |tag| [tag.id, tag] }.to_h
tags = Tag.where(id: tag_ids).to_a.each_with_object({}) { |tag, h| h[tag.id] = tag }
tag_ids.map { |tag_id| tags[tag_id] }.compact
end