From a16821802ee3f0848867f4b19c797009a2e33556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Thu, 14 May 2026 14:10:41 +0400 Subject: [PATCH] Fix PR review findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace copy-pasted New Relic URLs in Resend third-party entry with correct resend.com URLs and drop inapplicable fields - Escape single '%' instead of '%%' in LIKE pattern conversion so literal percent signs are not treated as wildcards - Return actual row ID from CommonTrackerPattern.Upsert via RETURNING id so conflict-path callers get the existing ID - Add ORDER BY id ASC to vendor-by-common-third-party query for deterministic LIMIT 1 selection Signed-off-by: Émile Ré Signed-off-by: Émile Ré --- cmd/common-tracker-patterns-import/main.go | 2 +- packages/third-parties/data.json | 15 ++++++-------- pkg/coredata/common_tracker_pattern.go | 24 ++++++++++++++-------- pkg/coredata/third_party.go | 1 + pkg/probo/tracker_mapping_worker.go | 4 +++- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/cmd/common-tracker-patterns-import/main.go b/cmd/common-tracker-patterns-import/main.go index 6d0d66b93..96f3c6700 100644 --- a/cmd/common-tracker-patterns-import/main.go +++ b/cmd/common-tracker-patterns-import/main.go @@ -176,7 +176,7 @@ func run() error { UpdatedAt: now, } - wasInserted, err := pattern.Upsert(ctx, tx) + _, wasInserted, err := pattern.Upsert(ctx, tx) if err != nil { return fmt.Errorf("cannot upsert common tracker pattern %q: %w", p.Pattern, err) } diff --git a/packages/third-parties/data.json b/packages/third-parties/data.json index 01e947225..9c6511006 100644 --- a/packages/third-parties/data.json +++ b/packages/third-parties/data.json @@ -1752,15 +1752,12 @@ "CCPA", "Data Privacy Framework (DPF)" ], - "securityPageUrl": "https://newrelic.com/security", - "privacyPolicyUrl": "https://newrelic.com/termsandconditions/privacy", - "termsOfServiceUrl": "https://newrelic.com/termsandconditions/terms", - "serviceLevelAgreementUrl": "https://docs.newrelic.com/docs/licenses/license-information/referenced-policies/service-level-availability-commitment/", - "dataProcessingAgreementUrl": "https://newrelic.com/sites/default/files/2023-11/New_Relic_GDPR_DPA_SCCs_Oct_2023_presigned.pdf", - "subprocessorsListUrl": "https://newrelic.com/sub-processors", - "businessAssociateAgreementUrl": "https://newrelic.com/termsandconditions/hipaabaafaq", - "trustPageUrl": "https://newrelic.com/security", - "statusPageUrl": "https://status.newrelic.com/", + "securityPageUrl": "https://resend.com/security", + "privacyPolicyUrl": "https://resend.com/legal/privacy-policy", + "termsOfServiceUrl": "https://resend.com/legal/terms-of-service", + "dataProcessingAgreementUrl": "https://resend.com/legal/dpa", + "subprocessorsListUrl": "https://resend.com/legal/subprocessors", + "trustPageUrl": "https://resend.com/security", "domains": [ "resend.com" ] diff --git a/pkg/coredata/common_tracker_pattern.go b/pkg/coredata/common_tracker_pattern.go index 7d622d93f..29b04881c 100644 --- a/pkg/coredata/common_tracker_pattern.go +++ b/pkg/coredata/common_tracker_pattern.go @@ -192,7 +192,7 @@ INSERT INTO common_tracker_patterns ( func (p CommonTrackerPattern) Upsert( ctx context.Context, conn pg.Tx, -) (inserted bool, err error) { +) (actualID gid.GID, inserted bool, err error) { q := ` INSERT INTO common_tracker_patterns ( id, @@ -224,7 +224,7 @@ SET description = EXCLUDED.description, confidence = EXCLUDED.confidence, updated_at = EXCLUDED.updated_at -RETURNING (xmax = 0) AS inserted +RETURNING id, (xmax = 0) AS inserted ` args := pgx.StrictNamedArgs{ @@ -242,16 +242,24 @@ RETURNING (xmax = 0) AS inserted rows, err := conn.Query(ctx, q, args) if err != nil { - return false, fmt.Errorf("cannot upsert common tracker pattern: %w", err) + return gid.GID{}, false, fmt.Errorf("cannot upsert common tracker pattern: %w", err) } defer rows.Close() - inserted, err = pgx.CollectExactlyOneRow(rows, pgx.RowTo[bool]) - if err != nil { - return false, fmt.Errorf("cannot collect upsert result: %w", err) + type upsertResult struct { + ID gid.GID + Inserted bool } - return inserted, nil + res, err := pgx.CollectExactlyOneRow(rows, func(row pgx.CollectableRow) (upsertResult, error) { + var r upsertResult + return r, row.Scan(&r.ID, &r.Inserted) + }) + if err != nil { + return gid.GID{}, false, fmt.Errorf("cannot collect upsert result: %w", err) + } + + return res.ID, res.Inserted, nil } func (p CommonTrackerPattern) Delete( @@ -301,7 +309,7 @@ WHERE (match_type = @match_type_glob AND @identifier LIKE replace(replace(replace(replace( - pattern, E'\\', E'\\\\'), '%%', E'\\%%'), '_', E'\\_'), '*', '%%') + pattern, E'\\', E'\\\\'), '%', E'\\%'), '_', E'\\_'), '*', '%') ESCAPE E'\\') OR (match_type = @match_type_exact AND pattern = @identifier) ) diff --git a/pkg/coredata/third_party.go b/pkg/coredata/third_party.go index af305cd5a..6013db90c 100644 --- a/pkg/coredata/third_party.go +++ b/pkg/coredata/third_party.go @@ -1358,6 +1358,7 @@ WHERE AND organization_id = @organization_id AND common_third_party_id = @common_third_party_id AND snapshot_id IS NULL +ORDER BY id ASC LIMIT 1; ` diff --git a/pkg/probo/tracker_mapping_worker.go b/pkg/probo/tracker_mapping_worker.go index d11a5480c..93d49675b 100644 --- a/pkg/probo/tracker_mapping_worker.go +++ b/pkg/probo/tracker_mapping_worker.go @@ -161,7 +161,8 @@ func (h *trackerMappingHandler) matchByDomain( UpdatedAt: now, } - if _, err := commonPattern.Upsert(ctx, tx); err != nil { + actualID, _, err := commonPattern.Upsert(ctx, tx) + if err != nil { h.logger.ErrorCtx( ctx, "cannot upsert common tracker pattern from domain match", @@ -170,6 +171,7 @@ func (h *trackerMappingHandler) matchByDomain( return nil, nil } + commonPattern.ID = actualID thirdPartyID := h.resolveThirdParty(ctx, tx, tp, &commonPattern) return &commonPattern.ID, thirdPartyID