about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-04-27 17:07:15 +0200
committerGitHub <noreply@github.com>2017-04-27 17:07:15 +0200
commitd4fedf84e024e0b5bb46707e3d1df08e8314485c (patch)
treed0f91049658ad31d629493cf9d634b29daec14e8 /app/models
parent2af4f3c4e22ab9a28a7fca49bee0ee2ed6256f27 (diff)
Cache Status#ancestors recursive query results (#2527)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/status.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index 4696ee289..d69765e96 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -91,7 +91,7 @@ class Status < ApplicationRecord
   end
 
   def ancestors(account = nil)
-    ids      = (Status.find_by_sql(['WITH RECURSIVE search_tree(id, in_reply_to_id, path) AS (SELECT id, in_reply_to_id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, statuses.in_reply_to_id, path || statuses.id FROM search_tree JOIN statuses ON statuses.id = search_tree.in_reply_to_id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path DESC', id]) - [self]).pluck(:id)
+    ids      = Rails.cache.fetch("ancestors:#{id}") { (Status.find_by_sql(['WITH RECURSIVE search_tree(id, in_reply_to_id, path) AS (SELECT id, in_reply_to_id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, statuses.in_reply_to_id, path || statuses.id FROM search_tree JOIN statuses ON statuses.id = search_tree.in_reply_to_id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path DESC', id]) - [self]).pluck(:id) }
     statuses = Status.where(id: ids).group_by(&:id)
     results  = ids.map { |id| statuses[id].first }
     results  = results.reject { |status| filter_from_context?(status, account) }