refactor duplicates search#630
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the duplicate-contact detection workflow to reduce unnecessary scanning by introducing a “blocking” candidate prefilter in SQL, and adds a grace-period scheduling mechanism (duplicates_check_due_at) so repeated profile edits coalesce into fewer duplicate-check runs.
Changes:
- Add
duplicates_check_due_at(plus supporting indexes) and wire it into duplicate-check selection and “mark as checked” behavior. - Refactor the duplicate similarity SQL to prefilter candidates via blocking conditions and reuse a single custom-field list per tenant batch run.
- Schedule duplicate checks after relevant profile/custom-field changes via
Contact.mark_duplicates_check_due.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pool/app/pool_database/tenant.ml | Registers the new tenant migration step. |
| pool/app/pool_database/migrations/migration_202607071000.ml | Adds duplicates_check_due_at column and multiple new DB indexes to support duplicate checks/search. |
| pool/app/duplicate_contacts/service.ml | Batches duplicate checks per tenant and reuses fetched custom fields across the batch. |
| pool/app/duplicate_contacts/repo.ml | Refactors similarity query to use blocking candidate selection; updates “find to check” to use duplicates_check_due_at and return multiple contacts. |
| pool/app/duplicate_contacts/duplicate_contacts.mli | Updates Service.run signature with optional pre-fetched fields. |
| pool/app/custom_field/repo/repo_partial_update.ml | Schedules duplicate checks when relevant custom-field/profile fields change. |
| pool/app/custom_field/event.ml | Schedules duplicate checks after custom-field answer mutations. |
| pool/app/contact/repo/repo.ml | Adds mark_duplicates_check_due and grace-period scheduling logic. |
| pool/app/contact/event.ml | Schedules duplicate checks on phone/profile updates. |
| pool/app/contact/contact.mli | Exposes mark_duplicates_check_due on the Contact API. |
| .gitignore | Ignores additional conflict-resolution artifact directories/files. |
Cover the new duplicates_check_due_at scheduling: the grace period set by mark_duplicates_check_due defers checks, find_to_check prioritizes due contacts and resumes them after the grace period, mark_as_checked resets the due date, the weekly periodic re-check still applies, and the service processes due contacts end to end. Exposes find_to_check, mark_as_checked and Service.run_by_tenant for the tests.
mabiede
force-pushed
the
feature/refactor-duplicates
branch
from
July 13, 2026 06:33
d639532 to
57c617b
Compare
PossessedC0bra
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.