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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user