about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-02-05 17:51:44 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-02-05 17:51:44 +0100
commit77e13c2bc93fdb633f27f94989ab5770f9ecc3b3 (patch)
treec9b139593bf3bd478bfaa2e44657492cfab33f94 /app
parent19b9e1e2c3d621b5f9f2367980dae62648fe22fa (diff)
Removing failed push notification API, make context loads use cache
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/v1/devices_controller.rb18
-rw-r--r--app/controllers/api/v1/statuses_controller.rb7
-rw-r--r--app/controllers/stream_entries_controller.rb4
-rw-r--r--app/models/favourite.rb2
-rw-r--r--app/models/status.rb8
5 files changed, 13 insertions, 26 deletions
diff --git a/app/controllers/api/v1/devices_controller.rb b/app/controllers/api/v1/devices_controller.rb
deleted file mode 100644
index c565e972b..000000000
--- a/app/controllers/api/v1/devices_controller.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-class Api::V1::DevicesController < ApiController
-  before_action -> { doorkeeper_authorize! :read }
-  before_action :require_user!
-
-  respond_to :json
-
-  def register
-    Device.where(account: current_account, registration_id: params[:registration_id]).first_or_create!(account: current_account, registration_id: params[:registration_id])
-    render_empty
-  end
-
-  def unregister
-    Device.where(account: current_account, registration_id: params[:registration_id]).delete_all
-    render_empty
-  end
-end
diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb
index 4b095a570..69cbdce5d 100644
--- a/app/controllers/api/v1/statuses_controller.rb
+++ b/app/controllers/api/v1/statuses_controller.rb
@@ -14,7 +14,12 @@ class Api::V1::StatusesController < ApiController
   end
 
   def context
-    @context = OpenStruct.new(ancestors: @status.in_reply_to_id.nil? ? [] : @status.ancestors(current_account), descendants: @status.descendants(current_account))
+    ancestors_results   = @status.in_reply_to_id.nil? ? [] : @status.ancestors(current_account)
+    descendants_results = @status.descendants(current_account)
+    loaded_ancestors    = cache_collection(ancestors_results, Status)
+    loaded_descendants  = cache_collection(descendants_results, Status)
+
+    @context = OpenStruct.new(ancestors: loaded_ancestors, descendants: loaded_descendants)
     statuses = [@status] + @context[:ancestors] + @context[:descendants]
 
     set_maps(statuses)
diff --git a/app/controllers/stream_entries_controller.rb b/app/controllers/stream_entries_controller.rb
index 5701b2efa..da284d80e 100644
--- a/app/controllers/stream_entries_controller.rb
+++ b/app/controllers/stream_entries_controller.rb
@@ -14,8 +14,8 @@ class StreamEntriesController < ApplicationController
         return gone if @stream_entry.activity.nil?
 
         if @stream_entry.activity_type == 'Status'
-          @ancestors   = @stream_entry.activity.ancestors(current_account)
-          @descendants = @stream_entry.activity.descendants(current_account)
+          @ancestors   = @stream_entry.activity.reply? ? cache_collection(@stream_entry.activity.ancestors(current_account), Status) : []
+          @descendants = cache_collection(@stream_entry.activity.descendants(current_account), Status)
         end
       end
 
diff --git a/app/models/favourite.rb b/app/models/favourite.rb
index 147105e48..3f3616dce 100644
--- a/app/models/favourite.rb
+++ b/app/models/favourite.rb
@@ -5,7 +5,7 @@ class Favourite < ApplicationRecord
   include Streamable
 
   belongs_to :account, inverse_of: :favourites
-  belongs_to :status,  inverse_of: :favourites, touch: true
+  belongs_to :status,  inverse_of: :favourites
 
   has_one :notification, as: :activity, dependent: :destroy
 
diff --git a/app/models/status.rb b/app/models/status.rb
index 63f5d5fa4..ab68f4e69 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -14,7 +14,7 @@ class Status < ApplicationRecord
   belongs_to :in_reply_to_account, foreign_key: 'in_reply_to_account_id', class_name: 'Account'
 
   belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies
-  belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, touch: true
+  belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs
 
   has_many :favourites, inverse_of: :status, dependent: :destroy
   has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy
@@ -81,7 +81,7 @@ class Status < ApplicationRecord
 
   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)
-    statuses = Status.where(id: ids).with_includes.group_by(&: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) }
 
@@ -90,7 +90,7 @@ class Status < ApplicationRecord
 
   def descendants(account = nil)
     ids      = (Status.find_by_sql(['WITH RECURSIVE search_tree(id, path) AS (SELECT id, ARRAY[id] FROM statuses WHERE id = ? UNION ALL SELECT statuses.id, path || statuses.id FROM search_tree JOIN statuses ON statuses.in_reply_to_id = search_tree.id WHERE NOT statuses.id = ANY(path)) SELECT id FROM search_tree ORDER BY path', id]) - [self]).pluck(:id)
-    statuses = Status.where(id: ids).with_includes.group_by(&: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) }
 
@@ -180,6 +180,6 @@ class Status < ApplicationRecord
   private
 
   def filter_from_context?(status, account)
-    account&.blocking?(status.account) || !status.permitted?(account)
+    account&.blocking?(status.account_id) || !status.permitted?(account)
   end
 end