Use subquery for common third party filter

Replace the two-step ID-materializing pattern (fetch IDs in Go, pass
as ANY(@ids)) with an IN-subquery that keeps the filtering entirely
in the database and eliminates an extra round trip. Remove the now
unused LoadIDsByCommonThirdPartyID and its service wrapper. Update
the coredata rule to clarify that subqueries for filtering are OK.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-05-28 21:36:04 +02:00
parent 44aca07de3
commit ed93301a1f
5 changed files with 55 additions and 120 deletions

View File

@@ -483,36 +483,3 @@ WHERE
return nil
}
// LoadIDsByCommonThirdPartyID returns just the IDs of the common tracker
// patterns linked to the given common third party. Callers use it to feed
// a `common_tracker_pattern_id = ANY(...)` filter on tracker_patterns
// without crossing the entity boundary.
func (ps *CommonTrackerPatterns) LoadIDsByCommonThirdPartyID(
ctx context.Context,
conn pg.Querier,
commonThirdPartyID gid.GID,
) ([]gid.GID, error) {
q := `
SELECT
id
FROM
common_tracker_patterns
WHERE
common_third_party_id = @common_third_party_id
`
args := pgx.StrictNamedArgs{"common_third_party_id": commonThirdPartyID}
rows, err := conn.Query(ctx, q, args)
if err != nil {
return nil, fmt.Errorf("cannot query common tracker pattern ids: %w", err)
}
ids, err := pgx.CollectRows(rows, pgx.RowTo[gid.GID])
if err != nil {
return nil, fmt.Errorf("cannot collect common tracker pattern ids: %w", err)
}
return ids, nil
}