Skip to content

refactor duplicates search#630

Merged
mabiede merged 4 commits into
mainfrom
feature/refactor-duplicates
Jul 14, 2026
Merged

refactor duplicates search#630
mabiede merged 4 commits into
mainfrom
feature/refactor-duplicates

Conversation

@mabiede

@mabiede mabiede commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@mabiede mabiede self-assigned this Jul 10, 2026
Copilot AI review requested due to automatic review settings July 10, 2026 07:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread pool/app/duplicate_contacts/repo.ml Outdated
Comment thread pool/app/duplicate_contacts/repo.ml Outdated
Comment thread pool/app/contact/repo/repo.ml
mabiede added 2 commits July 13, 2026 08:33
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
mabiede force-pushed the feature/refactor-duplicates branch from d639532 to 57c617b Compare July 13, 2026 06:33
@mabiede
mabiede merged commit 8b11d0b into main Jul 14, 2026
9 checks passed
@mabiede
mabiede deleted the feature/refactor-duplicates branch July 14, 2026 17:55
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.

3 participants