Remap unmapped trackers on new vendor domains

When the common-third-party enrichment worker discovers owned domains
for a vendor, tracker patterns that were detected and left unmatched
before those domains were known had nothing to re-trigger them.

Add RequestMappingForUnmappedByInitiatorDomains, a global re-arm that
stamps mapping_requested_at on still-unmapped patterns whose detected
trackers share one of the new domains, and call it from the enrichment
worker's persist step for newly-inserted domains only. The mapping
worker then re-resolves them through its existing domain-overlap path.

Targeting is limited to patterns with no resolved vendor (no org third
party and an absent or unlinked catalog row), so a pattern already
attributed to this or any other vendor is never disturbed.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-06-11 17:59:26 +02:00
parent 7649f19e33
commit 968895bdfd
3 changed files with 275 additions and 1 deletions

View File

@@ -372,10 +372,37 @@ func (h *enrichmentHandler) persist(
return fmt.Errorf("cannot persist common third party enrichment: %w", err)
}
var (
newDomains []string
remapped int64
)
for i := range domains {
if _, err := domains[i].Upsert(ctx, tx); err != nil {
inserted, err := domains[i].Upsert(ctx, tx)
if err != nil {
return fmt.Errorf("cannot upsert common third party domain: %w", err)
}
if inserted {
newDomains = append(newDomains, domains[i].Domain)
}
}
// A newly-discovered owned domain can resolve org tracker
// patterns that were detected and left unmapped before the
// domain was known. Re-arm those still-unmapped patterns so
// the mapping worker re-resolves them via its domain-overlap
// signal. Only newly-inserted domains trigger this: a re-run
// that rediscovers existing domains cascaded them already.
if len(newDomains) > 0 {
var patterns coredata.TrackerPatterns
n, err := patterns.RequestMappingForUnmappedByInitiatorDomains(ctx, tx, newDomains)
if err != nil {
return fmt.Errorf("cannot re-arm mapping for unmapped tracker patterns: %w", err)
}
remapped = n
}
h.logger.InfoCtx(
@@ -386,6 +413,8 @@ func (h *enrichmentHandler) persist(
log.String("status", payload.Status),
log.Bool("logo_stored", logoFile != nil),
log.Int("domains_stored", len(domains)),
log.Int("domains_new", len(newDomains)),
log.Int64("tracker_patterns_remapped", remapped),
)
return nil