Fix PR review findings

- 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é <emile@getprobo.com>
Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-05-14 14:10:41 +04:00
committed by Émile Ré
parent f52a4746fd
commit a16821802e
5 changed files with 27 additions and 19 deletions

View File

@@ -176,7 +176,7 @@ func run() error {
UpdatedAt: now, UpdatedAt: now,
} }
wasInserted, err := pattern.Upsert(ctx, tx) _, wasInserted, err := pattern.Upsert(ctx, tx)
if err != nil { if err != nil {
return fmt.Errorf("cannot upsert common tracker pattern %q: %w", p.Pattern, err) return fmt.Errorf("cannot upsert common tracker pattern %q: %w", p.Pattern, err)
} }

View File

@@ -1752,15 +1752,12 @@
"CCPA", "CCPA",
"Data Privacy Framework (DPF)" "Data Privacy Framework (DPF)"
], ],
"securityPageUrl": "https://newrelic.com/security", "securityPageUrl": "https://resend.com/security",
"privacyPolicyUrl": "https://newrelic.com/termsandconditions/privacy", "privacyPolicyUrl": "https://resend.com/legal/privacy-policy",
"termsOfServiceUrl": "https://newrelic.com/termsandconditions/terms", "termsOfServiceUrl": "https://resend.com/legal/terms-of-service",
"serviceLevelAgreementUrl": "https://docs.newrelic.com/docs/licenses/license-information/referenced-policies/service-level-availability-commitment/", "dataProcessingAgreementUrl": "https://resend.com/legal/dpa",
"dataProcessingAgreementUrl": "https://newrelic.com/sites/default/files/2023-11/New_Relic_GDPR_DPA_SCCs_Oct_2023_presigned.pdf", "subprocessorsListUrl": "https://resend.com/legal/subprocessors",
"subprocessorsListUrl": "https://newrelic.com/sub-processors", "trustPageUrl": "https://resend.com/security",
"businessAssociateAgreementUrl": "https://newrelic.com/termsandconditions/hipaabaafaq",
"trustPageUrl": "https://newrelic.com/security",
"statusPageUrl": "https://status.newrelic.com/",
"domains": [ "domains": [
"resend.com" "resend.com"
] ]

View File

@@ -192,7 +192,7 @@ INSERT INTO common_tracker_patterns (
func (p CommonTrackerPattern) Upsert( func (p CommonTrackerPattern) Upsert(
ctx context.Context, ctx context.Context,
conn pg.Tx, conn pg.Tx,
) (inserted bool, err error) { ) (actualID gid.GID, inserted bool, err error) {
q := ` q := `
INSERT INTO common_tracker_patterns ( INSERT INTO common_tracker_patterns (
id, id,
@@ -224,7 +224,7 @@ SET
description = EXCLUDED.description, description = EXCLUDED.description,
confidence = EXCLUDED.confidence, confidence = EXCLUDED.confidence,
updated_at = EXCLUDED.updated_at updated_at = EXCLUDED.updated_at
RETURNING (xmax = 0) AS inserted RETURNING id, (xmax = 0) AS inserted
` `
args := pgx.StrictNamedArgs{ args := pgx.StrictNamedArgs{
@@ -242,16 +242,24 @@ RETURNING (xmax = 0) AS inserted
rows, err := conn.Query(ctx, q, args) rows, err := conn.Query(ctx, q, args)
if err != nil { 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() defer rows.Close()
inserted, err = pgx.CollectExactlyOneRow(rows, pgx.RowTo[bool]) type upsertResult struct {
if err != nil { ID gid.GID
return false, fmt.Errorf("cannot collect upsert result: %w", err) 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( func (p CommonTrackerPattern) Delete(
@@ -301,7 +309,7 @@ WHERE
(match_type = @match_type_glob (match_type = @match_type_glob
AND @identifier LIKE AND @identifier LIKE
replace(replace(replace(replace( replace(replace(replace(replace(
pattern, E'\\', E'\\\\'), '%%', E'\\%%'), '_', E'\\_'), '*', '%%') pattern, E'\\', E'\\\\'), '%', E'\\%'), '_', E'\\_'), '*', '%')
ESCAPE E'\\') ESCAPE E'\\')
OR (match_type = @match_type_exact AND pattern = @identifier) OR (match_type = @match_type_exact AND pattern = @identifier)
) )

View File

@@ -1358,6 +1358,7 @@ WHERE
AND organization_id = @organization_id AND organization_id = @organization_id
AND common_third_party_id = @common_third_party_id AND common_third_party_id = @common_third_party_id
AND snapshot_id IS NULL AND snapshot_id IS NULL
ORDER BY id ASC
LIMIT 1; LIMIT 1;
` `

View File

@@ -161,7 +161,8 @@ func (h *trackerMappingHandler) matchByDomain(
UpdatedAt: now, UpdatedAt: now,
} }
if _, err := commonPattern.Upsert(ctx, tx); err != nil { actualID, _, err := commonPattern.Upsert(ctx, tx)
if err != nil {
h.logger.ErrorCtx( h.logger.ErrorCtx(
ctx, ctx,
"cannot upsert common tracker pattern from domain match", "cannot upsert common tracker pattern from domain match",
@@ -170,6 +171,7 @@ func (h *trackerMappingHandler) matchByDomain(
return nil, nil return nil, nil
} }
commonPattern.ID = actualID
thirdPartyID := h.resolveThirdParty(ctx, tx, tp, &commonPattern) thirdPartyID := h.resolveThirdParty(ctx, tx, tp, &commonPattern)
return &commonPattern.ID, thirdPartyID return &commonPattern.ID, thirdPartyID