Compare commits

...

1 commit

Author SHA1 Message Date
Eugen Rochko
25843710c3 Fix error when response contains reblogs of soft-deleted statuses in REST API 2022-04-30 06:22:01 +02:00
2 changed files with 8 additions and 12 deletions

View file

@ -336,22 +336,18 @@ class Status < ApplicationRecord
end
def reload_stale_associations!(cached_items)
account_ids = []
cached_items.each do |item|
account_ids << item.account_id
account_ids << item.reblog.account_id if item.reblog?
end
account_ids.uniq!
account_ids = cached_items.each_with_object([]) do |item, arr|
arr << item.account_id
arr << item.reblog&.account_id if item.reblog?
end.compact.uniq
return if account_ids.empty?
accounts = Account.where(id: account_ids).includes(:account_stat, :user).index_by(&:id)
accounts_map = Account.where(id: account_ids).includes(:account_stat, :user).index_by(&:id)
cached_items.each do |item|
item.account = accounts[item.account_id]
item.reblog.account = accounts[item.reblog.account_id] if item.reblog?
item.account = accounts_map[item.account_id]
item.reblog.account = accounts_map[item.reblog.account_id] if item.reblog? && item.reblog
end
end

View file

@ -15,7 +15,7 @@ class StatusRelationshipsPresenter
statuses = statuses.compact
status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact
conversation_ids = statuses.filter_map(&:conversation_id).uniq
pinnable_status_ids = statuses.map(&:proper).filter_map { |s| s.id if s.account_id == current_account_id && %w(public unlisted private).include?(s.visibility) }
pinnable_status_ids = statuses.filter_map(&:proper).filter_map { |s| s.id if s.account_id == current_account_id && %w(public unlisted private).include?(s.visibility) }
@reblogs_map = Status.reblogs_map(status_ids, current_account_id).merge(options[:reblogs_map] || {})
@favourites_map = Status.favourites_map(status_ids, current_account_id).merge(options[:favourites_map] || {})