mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 07:34:45 +02:00
decrease db load
This commit is contained in:
parent
7477cf8dbe
commit
577c7e0209
4 changed files with 59 additions and 29 deletions
|
@ -1,12 +1,12 @@
|
|||
class VerifyEmailsJob < ApplicationJob
|
||||
discard_on StandardError
|
||||
|
||||
def perform(contact_id:, check_level: 'regex')
|
||||
contact = Contact.find_by(id: contact_id)
|
||||
def perform(contact:, check_level: 'regex')
|
||||
# contact = Contact.find_by(id: contact_id)
|
||||
|
||||
return if check_contact_for_duplicate_mail(contact_id)
|
||||
# return if check_contact_for_duplicate_mail(contact)
|
||||
|
||||
contact_not_found(contact_id) unless contact
|
||||
contact_not_found(contact.id) unless contact
|
||||
validate_check_level(check_level)
|
||||
action = Actions::EmailCheck.new(email: contact.email,
|
||||
validation_eventable: contact,
|
||||
|
@ -19,15 +19,14 @@ class VerifyEmailsJob < ApplicationJob
|
|||
|
||||
private
|
||||
|
||||
def check_contact_for_duplicate_mail(contact_id)
|
||||
time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
|
||||
contact = Contact.find(contact_id)
|
||||
contact_ids = Contact.where(email: contact.email).where('created_at > ?', time).pluck(:id)
|
||||
|
||||
r = ValidationEvent.where(validation_eventable_id: contact_ids).order(created_at: :desc)
|
||||
|
||||
r.present?
|
||||
end
|
||||
# def check_contact_for_duplicate_mail(contact)
|
||||
# time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
|
||||
# contact_ids = Contact.where(email: contact.email).where('created_at > ?', time).pluck(:id)
|
||||
#
|
||||
# r = ValidationEvent.where(validation_eventable_id: contact_ids).order(created_at: :desc)
|
||||
#
|
||||
# r.present?
|
||||
# end
|
||||
|
||||
def contact_not_found(contact_id)
|
||||
raise StandardError, "Contact with contact_id #{contact_id} not found"
|
||||
|
|
|
@ -12,7 +12,7 @@ class ValidationEvent < ApplicationRecord
|
|||
|
||||
INVALID_EVENTS_COUNT_BY_LEVEL = {
|
||||
regex: 1,
|
||||
mx: 3,
|
||||
mx: 2,
|
||||
smtp: 1,
|
||||
}.freeze
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue