Class: Audience::PartyBackfill
- Inherits:
-
Object
- Object
- Audience::PartyBackfill
- Defined in:
- app/services/audience/party_backfill.rb
Overview
Resolves and persists the customer (party) for each unresolved audience_member on
a static email list by matching its email_address against the CRM:
- Contacts first — the most recently created Contact (that has a customer)
carrying this email; we store that Contact'scustomer_id, i.e. its
implicit customer. - Customers next — if no Contact matches, the most recently created
Customer holding this email directly; we store its own id.
"Most recent wins" breaks ties when several parties of the same type share
one email. Only unresolved (customer_id IS NULL), live (archived_at IS NULL) audience_members are touched, so the pass is idempotent and re-runnable.
Writing customer_id onto email audience_members is safe because migration
20260630053002 scoped the customer-uniqueness index to email-less rows — two
contacts under one customer can co-exist on the same email list, deduped by
email rather than customer.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #call ⇒ Result
-
#initialize(audience) ⇒ PartyBackfill
constructor
A new instance of PartyBackfill.
Constructor Details
#initialize(audience) ⇒ PartyBackfill
Returns a new instance of PartyBackfill.
28 29 30 |
# File 'app/services/audience/party_backfill.rb', line 28 def initialize(audience) @audience = audience end |