about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-03-11 16:47:36 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-03-11 16:47:36 +0100
commit447cfef62d74a670ddd600c0240f41746ac2fe0a (patch)
tree5c3ed8838f90435b4c4c52a366059cbbd2a24a67 /app/models
parentb919f39b3186c5f022d3965cf6023ff9041e91ca (diff)
Improving feed queries, switching API to doorkeeper authentication
Diffstat (limited to 'app/models')
-rw-r--r--app/models/feed.rb2
-rw-r--r--app/models/status.rb3
2 files changed, 4 insertions, 1 deletions
diff --git a/app/models/feed.rb b/app/models/feed.rb
index a063ad05b..0c0b8ae2c 100644
--- a/app/models/feed.rb
+++ b/app/models/feed.rb
@@ -11,7 +11,7 @@ class Feed
     # If we're after most recent items and none are there, we need to precompute the feed
     return PrecomputeFeedService.new.(@type, @account).take(limit) if unhydrated.empty? && offset == 0
 
-    Status.where(id: unhydrated).each { |status| status_map[status.id.to_s] = status }
+    Status.where(id: unhydrated).with_includes.with_counters.each { |status| status_map[status.id.to_s] = status }
     return unhydrated.map { |id| status_map[id] }
   end
 
diff --git a/app/models/status.rb b/app/models/status.rb
index 7e0c334ec..4fedad107 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -14,6 +14,9 @@ class Status < ActiveRecord::Base
   validates :account, presence: true
   validates :uri, uniqueness: true, unless: 'local?'
 
+  scope :with_counters, -> { select('statuses.*, (select count(r.id) from statuses as r where r.reblog_of_id = statuses.id) as reblogs_count, (select count(f.id) from favourites as f where f.status_id = statuses.id) as favourites_count') }
+  scope :with_includes, -> { includes(:account, reblog: :account, thread: :account) }
+
   def local?
     self.uri.nil?
   end