Backfill tracker description from common catalog
When the mapping worker resolves a CommonTrackerPattern, propagate its description back to the org TrackerPattern if the latter is still empty. This ensures agent-produced descriptions reach the user-facing tracker instead of staying only in the catalog. The Update method now covers all mutable TrackerPattern columns including common_tracker_pattern_id and third_party_id, replacing the removed UpdateMapping method. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -159,7 +159,19 @@ func (h *trackerMappingHandler) Process(ctx context.Context, tp coredata.Tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
if commonPatternID != nil || thirdPartyID != nil {
|
if commonPatternID != nil || thirdPartyID != nil {
|
||||||
if err := tp.UpdateMapping(ctx, tx, commonPatternID, thirdPartyID); err != nil {
|
tp.CommonTrackerPatternID = commonPatternID
|
||||||
|
tp.ThirdPartyID = thirdPartyID
|
||||||
|
tp.UpdatedAt = time.Now()
|
||||||
|
|
||||||
|
if tp.Description == "" && commonPatternID != nil {
|
||||||
|
var commonPattern coredata.CommonTrackerPattern
|
||||||
|
if err := commonPattern.LoadByID(ctx, tx, *commonPatternID); err == nil && commonPattern.Description != "" {
|
||||||
|
tp.Description = commonPattern.Description
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scope := coredata.NewScopeFromObjectID(tp.ID)
|
||||||
|
if err := tp.Update(ctx, tx, scope); err != nil {
|
||||||
return fmt.Errorf("cannot update tracker pattern mapping: %w", err)
|
return fmt.Errorf("cannot update tracker pattern mapping: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -505,6 +505,8 @@ func (tp *TrackerPattern) Update(
|
|||||||
q := `
|
q := `
|
||||||
UPDATE tracker_patterns
|
UPDATE tracker_patterns
|
||||||
SET
|
SET
|
||||||
|
common_tracker_pattern_id = @common_tracker_pattern_id,
|
||||||
|
third_party_id = @third_party_id,
|
||||||
cookie_category_id = @cookie_category_id,
|
cookie_category_id = @cookie_category_id,
|
||||||
display_name = @display_name,
|
display_name = @display_name,
|
||||||
max_age_seconds = @max_age_seconds,
|
max_age_seconds = @max_age_seconds,
|
||||||
@@ -522,6 +524,8 @@ WHERE
|
|||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
args := pgx.StrictNamedArgs{
|
||||||
"id": tp.ID,
|
"id": tp.ID,
|
||||||
|
"common_tracker_pattern_id": tp.CommonTrackerPatternID,
|
||||||
|
"third_party_id": tp.ThirdPartyID,
|
||||||
"cookie_category_id": tp.CookieCategoryID,
|
"cookie_category_id": tp.CookieCategoryID,
|
||||||
"display_name": tp.DisplayName,
|
"display_name": tp.DisplayName,
|
||||||
"max_age_seconds": tp.MaxAgeSeconds,
|
"max_age_seconds": tp.MaxAgeSeconds,
|
||||||
@@ -1106,40 +1110,3 @@ WHERE id = @id
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *TrackerPattern) UpdateMapping(
|
|
||||||
ctx context.Context,
|
|
||||||
tx pg.Tx,
|
|
||||||
commonTrackerPatternID *gid.GID,
|
|
||||||
thirdPartyID *gid.GID,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
UPDATE tracker_patterns
|
|
||||||
SET
|
|
||||||
common_tracker_pattern_id = @common_tracker_pattern_id,
|
|
||||||
third_party_id = @third_party_id,
|
|
||||||
mapping_requested_at = NULL,
|
|
||||||
updated_at = @updated_at
|
|
||||||
WHERE id = @id
|
|
||||||
`
|
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
args := pgx.StrictNamedArgs{
|
|
||||||
"id": tp.ID,
|
|
||||||
"common_tracker_pattern_id": commonTrackerPatternID,
|
|
||||||
"third_party_id": thirdPartyID,
|
|
||||||
"updated_at": now,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := tx.Exec(ctx, q, args)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot update tracker pattern mapping: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tp.CommonTrackerPatternID = commonTrackerPatternID
|
|
||||||
tp.ThirdPartyID = thirdPartyID
|
|
||||||
tp.MappingRequestedAt = nil
|
|
||||||
tp.UpdatedAt = now
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user