Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check force delete lift bug #2418

Merged
merged 11 commits into from
Oct 12, 2022
Merged

Fix check force delete lift bug #2418

merged 11 commits into from
Oct 12, 2022

Conversation

thiagoyoussef
Copy link
Member

@thiagoyoussef thiagoyoussef commented Aug 14, 2022

close #2413

@viezly
Copy link

viezly bot commented Aug 14, 2022

Changes preview:

Legend:

👀 Review pull request on Viezly

@thiagoyoussef thiagoyoussef force-pushed the 2413-force-delete-lift-bug branch 2 times, most recently from 495b068 to 1bc743c Compare August 15, 2022 00:37
@OlegPhenomenon OlegPhenomenon self-requested a review August 16, 2022 07:31
@@ -3,8 +3,7 @@ task check_force_delete: :environment do
validations = ValidationEvent.failed.where(validation_eventable_type: 'Contact').uniq(&:validation_eventable_id)

invalid_contact_ids = validations.select do |validation|
contact = validation.validation_eventable
contact.need_to_start_force_delete? || contact.need_to_lift_force_delete?
validation.validation_eventable.need_to_start_force_delete?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did you hide the check for need_to_lift_force_delete? how will he understand that force delete can be removed on a specific domain?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added on the validation_event after create callback. It's the way we did before I refactor it
I moved back because it seems that after updating to a valid email, the domain didn't have the FD status notes refreshed

@@ -35,6 +35,8 @@ class ValidationEvent < ApplicationRecord
scope :smtp, -> { where('event_data @> ?', { 'check_level': 'smtp' }.to_json) }
scope :by_object, ->(object) { where(validation_eventable: object) }

after_create :check_force_delete_lift

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a bad idea.

The last time we put checks for force delete and lift force delete into callbacks, firstly there were performance issues, and secondly, unexpected behavior happened when lift force delete worked in a situation where it was not supposed to.

In addition, there is an opinion that using callback is not a good practice in terms of support, code testing. But that's just an opinion, everyone has their own opinion :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add one more comment to make it a little clearer.

We have a validation_event model, we also have a verify_email rake task. When we run this task, the mail is validated and the results are written to the validation_event table. The problem is that checking mail is a very productive operation. And if, in addition to checking mail, writing the result data, you also check for check force delete lift, this will be a VERY highly productive operation. My idea is to remove after_create :check_force_delete_lift. It should not be launched every time after checking each email and record results to validation event table, because it takes a LOT of resources. It is enough that all emails are checked and the results are recorded in the validation table. We can run the Force Delete check and removal separately, we don’t need to run the force delete lift check in the valiation_event model

@thiagoyoussef thiagoyoussef force-pushed the 2413-force-delete-lift-bug branch from dc57f47 to df7a112 Compare September 18, 2022 20:46
@thiagoyoussef thiagoyoussef force-pushed the 2413-force-delete-lift-bug branch from cb66ad1 to 71d1e9b Compare September 25, 2022 13:31
domain.reload

assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_email
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were we checking if the status notes had the invalid email? It seems strange to me, as the purpose of the test is to check if the invalid email was removed from the status notes.
Changed the test to assert_nil

@@ -35,6 +35,8 @@ class ValidationEvent < ApplicationRecord
scope :smtp, -> { where('event_data @> ?', { 'check_level': 'smtp' }.to_json) }
scope :by_object, ->(object) { where(validation_eventable: object) }

after_create :check_force_delete_lift

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add one more comment to make it a little clearer.

We have a validation_event model, we also have a verify_email rake task. When we run this task, the mail is validated and the results are written to the validation_event table. The problem is that checking mail is a very productive operation. And if, in addition to checking mail, writing the result data, you also check for check force delete lift, this will be a VERY highly productive operation. My idea is to remove after_create :check_force_delete_lift. It should not be launched every time after checking each email and record results to validation event table, because it takes a LOT of resources. It is enough that all emails are checked and the results are recorded in the validation table. We can run the Force Delete check and removal separately, we don’t need to run the force delete lift check in the valiation_event model

@vohmar
Copy link
Contributor

vohmar commented Oct 11, 2022

an issue detected - if user has the same invalid email with multiple contact objects related to a single domain registration the amount of false validation_event records is unlimited (seemingly) instead of three records. This is not a rare case in production

@vohmar vohmar merged commit 4a0dc8e into master Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ForceDelete lift task fails to lift
4 participants