about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2017-10-16 01:29:02 -0500
committerDavid Yip <yipdw@member.fsf.org>2017-10-16 01:29:02 -0500
commit6cd5b3bbe5a11fcf25bbefba2803f2ae840f39fc (patch)
tree4bb60f4493fb70cada728a373f74c18b87e8f95d /app/models
parentf72ad67a3967230afd63a9e2d84a2a69331c4787 (diff)
parent894da3dcca781e27ce9c5130f1021526ac8a6887 (diff)
Merge remote-tracking branch 'origin/master' into gs-master
Diffstat (limited to 'app/models')
-rw-r--r--app/models/notification.rb5
-rw-r--r--app/models/status.rb12
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