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:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
|
||||
@@ -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;
|
||||
`
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user