From 45c7ee39b3d45159de382e8596110af04ee1ed8c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 22 Nov 2016 17:32:51 +0100 Subject: Remove unneeded indices, improve error handling in background workers, don't needlessly reload reblogged status, send Devise e-mails asynchronously --- app/models/notification.rb | 2 ++ app/models/user.rb | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'app/models') diff --git a/app/models/notification.rb b/app/models/notification.rb index 419f31230..c0537397c 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -11,6 +11,8 @@ class Notification < ApplicationRecord belongs_to :follow, foreign_type: 'Follow', 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 scope :with_includes, -> { includes(status: STATUS_INCLUDES, mention: [status: STATUS_INCLUDES], favourite: [:account, status: STATUS_INCLUDES], follow: :account) } diff --git a/app/models/user.rb b/app/models/user.rb index 4eb1d20a5..7e3547dff 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,4 +16,8 @@ class User < ApplicationRecord has_settings do |s| s.key :notification_emails, defaults: { follow: true, reblog: true, favourite: true, mention: true } end + + def send_devise_notification(notification, *args) + devise_mailer.send(notification, self, *args).deliver_later + end end -- cgit