Remove unneeded indices, improve error handling in background workers, don't needlessly reload reblogged status, send Devise e-mails asynchronously

signup-info-prompt
Eugen Rochko 2016-11-22 17:32:51 +01:00
parent 95db6cbe28
commit 45c7ee39b3
8 changed files with 20 additions and 6 deletions

View File

@ -54,7 +54,7 @@ class Api::V1::StatusesController < ApiController
end end
def reblog def reblog
@status = ReblogService.new.call(current_user.account, Status.find(params[:id])).reload @status = ReblogService.new.call(current_user.account, Status.find(params[:id]))
render action: :show render action: :show
end end

View File

@ -11,6 +11,8 @@ class Notification < ApplicationRecord
belongs_to :follow, foreign_type: 'Follow', foreign_key: 'activity_id' belongs_to :follow, foreign_type: 'Follow', foreign_key: 'activity_id'
belongs_to :favourite, foreign_type: 'Favourite', foreign_key: 'activity_id' belongs_to :favourite, foreign_type: 'Favourite', foreign_key: 'activity_id'
validates :account_id, uniqueness: { scope: [:activity_type, :activity_id] }
STATUS_INCLUDES = [:account, :stream_entry, :media_attachments, :tags, mentions: :account, reblog: [:stream_entry, :account, :media_attachments, :tags, mentions: :account]].freeze STATUS_INCLUDES = [:account, :stream_entry, :media_attachments, :tags, mentions: :account, reblog: [:stream_entry, :account, :media_attachments, :tags, mentions: :account]].freeze
scope :with_includes, -> { includes(status: STATUS_INCLUDES, mention: [status: STATUS_INCLUDES], favourite: [:account, status: STATUS_INCLUDES], follow: :account) } scope :with_includes, -> { includes(status: STATUS_INCLUDES, mention: [status: STATUS_INCLUDES], favourite: [:account, status: STATUS_INCLUDES], follow: :account) }

View File

@ -16,4 +16,8 @@ class User < ApplicationRecord
has_settings do |s| has_settings do |s|
s.key :notification_emails, defaults: { follow: true, reblog: true, favourite: true, mention: true } s.key :notification_emails, defaults: { follow: true, reblog: true, favourite: true, mention: true }
end end
def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
end
end end

View File

@ -10,6 +10,8 @@ class NotifyService < BaseService
create_notification create_notification
send_email if email_enabled? send_email if email_enabled?
rescue ActiveRecord::RecordInvalid
return
end end
private private

View File

@ -61,7 +61,7 @@ class ProcessFeedService < BaseService
status.save! status.save!
NotifyService.new.call(status.reblog.account, status) if status.reblog? NotifyService.new.call(status.reblog.account, status) if status.reblog? && status.reblog.account.local?
Rails.logger.debug "Queuing remote status #{status.id} (#{id}) for distribution" Rails.logger.debug "Queuing remote status #{status.id} (#{id}) for distribution"
DistributionWorker.perform_async(status.id) DistributionWorker.perform_async(status.id)
status status

View File

@ -5,5 +5,7 @@ class SalmonWorker
def perform(account_id, body) def perform(account_id, body)
ProcessInteractionService.new.call(body, Account.find(account_id)) ProcessInteractionService.new.call(body, Account.find(account_id))
rescue ActiveRecord::RecordNotFound
true
end end
end end

View File

@ -0,0 +1,7 @@
class RemoveUnneededIndexes < ActiveRecord::Migration[5.0]
def change
remove_index :notifications, name: "index_notifications_on_account_id"
remove_index :settings, name: "index_settings_on_target_type_and_target_id"
remove_index :statuses_tags, name: "index_statuses_tags_on_tag_id"
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161119211120) do ActiveRecord::Schema.define(version: 20161122163057) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -103,7 +103,6 @@ ActiveRecord::Schema.define(version: 20161119211120) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["account_id", "activity_id", "activity_type"], name: "account_activity", unique: true, using: :btree t.index ["account_id", "activity_id", "activity_type"], name: "account_activity", unique: true, using: :btree
t.index ["account_id"], name: "index_notifications_on_account_id", using: :btree
end end
create_table "oauth_access_grants", force: :cascade do |t| create_table "oauth_access_grants", force: :cascade do |t|
@ -152,7 +151,6 @@ ActiveRecord::Schema.define(version: 20161119211120) do
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.index ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree t.index ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree
t.index ["target_type", "target_id"], name: "index_settings_on_target_type_and_target_id", using: :btree
end end
create_table "statuses", force: :cascade do |t| create_table "statuses", force: :cascade do |t|
@ -174,7 +172,6 @@ ActiveRecord::Schema.define(version: 20161119211120) do
t.integer "status_id", null: false t.integer "status_id", null: false
t.integer "tag_id", null: false t.integer "tag_id", null: false
t.index ["tag_id", "status_id"], name: "index_statuses_tags_on_tag_id_and_status_id", unique: true, using: :btree t.index ["tag_id", "status_id"], name: "index_statuses_tags_on_tag_id_and_status_id", unique: true, using: :btree
t.index ["tag_id"], name: "index_statuses_tags_on_tag_id", using: :btree
end end
create_table "stream_entries", force: :cascade do |t| create_table "stream_entries", force: :cascade do |t|