From 979486020e52e7dd971203b2c86ce4d6b5e1a451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Thu, 28 May 2026 21:59:02 +0200 Subject: [PATCH] Backfill tracker description from common catalog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é --- pkg/cookiebanner/tracker_mapping_worker.go | 14 ++++- pkg/coredata/tracker_pattern.go | 59 +++++----------------- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/pkg/cookiebanner/tracker_mapping_worker.go b/pkg/cookiebanner/tracker_mapping_worker.go index 6b3bfa07a..be26d0793 100644 --- a/pkg/cookiebanner/tracker_mapping_worker.go +++ b/pkg/cookiebanner/tracker_mapping_worker.go @@ -159,7 +159,19 @@ func (h *trackerMappingHandler) Process(ctx context.Context, tp coredata.Tracker } 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) } diff --git a/pkg/coredata/tracker_pattern.go b/pkg/coredata/tracker_pattern.go index ead816265..92acde0b8 100644 --- a/pkg/coredata/tracker_pattern.go +++ b/pkg/coredata/tracker_pattern.go @@ -505,6 +505,8 @@ func (tp *TrackerPattern) Update( q := ` UPDATE tracker_patterns SET + common_tracker_pattern_id = @common_tracker_pattern_id, + third_party_id = @third_party_id, cookie_category_id = @cookie_category_id, display_name = @display_name, max_age_seconds = @max_age_seconds, @@ -521,15 +523,17 @@ WHERE q = fmt.Sprintf(q, scope.SQLFragment()) args := pgx.StrictNamedArgs{ - "id": tp.ID, - "cookie_category_id": tp.CookieCategoryID, - "display_name": tp.DisplayName, - "max_age_seconds": tp.MaxAgeSeconds, - "description": tp.Description, - "excluded": tp.Excluded, - "source": tp.Source, - "last_matched_at": tp.LastMatchedAt, - "updated_at": tp.UpdatedAt, + "id": tp.ID, + "common_tracker_pattern_id": tp.CommonTrackerPatternID, + "third_party_id": tp.ThirdPartyID, + "cookie_category_id": tp.CookieCategoryID, + "display_name": tp.DisplayName, + "max_age_seconds": tp.MaxAgeSeconds, + "description": tp.Description, + "excluded": tp.Excluded, + "source": tp.Source, + "last_matched_at": tp.LastMatchedAt, + "updated_at": tp.UpdatedAt, } maps.Copy(args, scope.SQLArguments()) @@ -1106,40 +1110,3 @@ WHERE id = @id 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 -}