0
0
Fork 0

Moving Salmon notifications to background processing, fixing mini-profiler

behaviour with Turbolinks enabled, optimizing Rabl for production
This commit is contained in:
Eugen Rochko 2016-03-26 13:42:10 +01:00
parent da4b675aca
commit 85b00d19b8
15 changed files with 49 additions and 35 deletions

View file

@ -1,2 +1,5 @@
$(document).on 'turbolinks:load', ->
window.MiniProfiler.pageTransition() unless typeof window.MiniProfiler == 'undefined'
$ ->
$(document).on 'turbolinks:load', ->
unless typeof window.MiniProfiler == 'undefined'
window.MiniProfiler.init()
window.MiniProfiler.pageTransition()

View file

@ -16,7 +16,7 @@ class Auth::RegistrationsController < Devise::RegistrationsController
end
end
def after_sign_up_path_for(resource)
def after_sign_up_path_for(_resource)
root_path
end
end

View file

@ -17,7 +17,7 @@ class Status < ActiveRecord::Base
validates :text, presence: true, if: Proc.new { |s| s.local? && !s.reblog? }
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, :mentions, :stream_entry, reblog: [:account, :mentions], thread: [:account, :mentions]) }
scope :with_includes, -> { includes(:account, :mentions, :stream_entry, reblog: [:account, :mentions], thread: :account) }
def local?
self.uri.nil?

View file

@ -10,15 +10,9 @@ class FavouriteService < BaseService
if status.local?
NotificationMailer.favourite(status, account).deliver_later
else
send_interaction_service.(favourite.stream_entry, status.account)
NotificationWorker.perform_async(favourite.stream_entry.id, status.account_id)
end
favourite
end
private
def send_interaction_service
@send_interaction_service ||= SendInteractionService.new
end
end

View file

@ -8,7 +8,7 @@ class FollowService < BaseService
return nil if target_account.nil?
follow = source_account.follow!(target_account)
send_interaction_service.(follow.stream_entry, target_account)
NotificationWorker.perform_async(follow.stream_entry.id, target_account.id)
source_account.ping!(account_url(source_account, format: 'atom'), [Rails.configuration.x.hub_url])
follow
end
@ -18,8 +18,4 @@ class FollowService < BaseService
def follow_remote_account_service
@follow_remote_account_service ||= FollowRemoteAccountService.new
end
def send_interaction_service
@send_interaction_service ||= SendInteractionService.new
end
end

View file

@ -24,7 +24,7 @@ class ProcessMentionsService < BaseService
if mentioned_account.local?
NotificationMailer.mention(mentioned_account, status).deliver_later
else
send_interaction_service.(status.stream_entry, mentioned_account)
NotificationWorker.perform_async(status.stream_entry.id, mentioned_account.id)
end
end
end
@ -34,8 +34,4 @@ class ProcessMentionsService < BaseService
def follow_remote_account_service
@follow_remote_account_service ||= FollowRemoteAccountService.new
end
def send_interaction_service
@send_interaction_service ||= SendInteractionService.new
end
end

View file

@ -5,13 +5,13 @@ class ReblogService < BaseService
# @return [Status]
def call(account, reblogged_status)
reblog = account.statuses.create!(reblog: reblogged_status, text: '')
fan_out_on_write_service.(reblog)
DistributionWorker.perform_async(reblog.id)
account.ping!(account_url(account, format: 'atom'), [Rails.configuration.x.hub_url])
if reblogged_status.local?
NotificationMailer.reblog(reblogged_status, account).deliver_later
else
send_interaction_service.(reblog.stream_entry, reblogged_status.account)
NotificationWorker.perform_async(reblog.stream_entry.id, reblogged_status.account_id)
end
reblog
@ -22,8 +22,4 @@ class ReblogService < BaseService
def send_interaction_service
@send_interaction_service ||= SendInteractionService.new
end
def fan_out_on_write_service
@fan_out_on_write_service ||= FanOutOnWriteService.new
end
end

View file

@ -4,12 +4,6 @@ class UnfollowService < BaseService
# @param [Account] target_account Which to unfollow
def call(source_account, target_account)
follow = source_account.unfollow!(target_account)
send_interaction_service.(follow.stream_entry, target_account) unless target_account.local?
end
private
def send_interaction_service
@send_interaction_service ||= SendInteractionService.new
NotificationWorker.perform_async(follow.stream_entry.id, target_account.id) unless target_account.local?
end
end

View file

@ -0,0 +1,7 @@
class NotificationWorker
include Sidekiq::Worker
def perform(stream_entry_id, target_account_id)
SendInteractionService.new.(StreamEntry.find(stream_entry_id), Account.find(target_account_id))
end
end