diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/notification.rb | 5 | ||||
-rw-r--r-- | app/models/status.rb | 12 |
2 files changed, 11 insertions, 6 deletions
diff --git a/app/models/notification.rb b/app/models/notification.rb index 1e64d1ae9..0a5d987cf 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -68,7 +68,10 @@ class Notification < ApplicationRecord class << self def reload_stale_associations!(cached_items) account_ids = cached_items.map(&:from_account_id).uniq - accounts = Account.where(id: account_ids).map { |a| [a.id, a] }.to_h + + return if account_ids.empty? + + accounts = Account.where(id: account_ids).map { |a| [a.id, a] }.to_h cached_items.each do |item| item.from_account = accounts[item.from_account_id] diff --git a/app/models/status.rb b/app/models/status.rb index 107ccface..30d53f298 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -134,7 +134,7 @@ class Status < ApplicationRecord CustomEmoji.from_text([spoiler_text, text].join(' '), account.domain) end - after_create :store_uri, if: :local? + after_create_commit :store_uri, if: :local? around_create Mastodon::Snowflake::Callbacks @@ -194,7 +194,11 @@ class Status < ApplicationRecord account_ids << item.reblog.account_id if item.reblog? end - accounts = Account.where(id: account_ids.uniq).map { |a| [a.id, a] }.to_h + account_ids.uniq! + + return if account_ids.empty? + + accounts = Account.where(id: account_ids).map { |a| [a.id, a] }.to_h cached_items.each do |item| item.account = accounts[item.account_id] @@ -216,9 +220,7 @@ class Status < ApplicationRecord # non-followers can see everything that isn't private/direct, but can see stuff they are mentioned in. visibility.push(:private) if account.following?(target_account) - joins("LEFT OUTER JOIN mentions ON statuses.id = mentions.status_id AND mentions.account_id = #{account.id}") - .where(arel_table[:visibility].in(visibility).or(Mention.arel_table[:id].not_eq(nil))) - .order(visibility: :desc) + where(visibility: visibility).or(where(id: account.mentions.select(:status_id))) end end |