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

@@ -2746,40 +2746,6 @@ func (s *Service) GetCommonTrackerPatternsByIDs(
return patterns, nil
}
// LoadCommonTrackerPatternIDsByCommonThirdPartyID returns the IDs of
// every common tracker pattern referencing the given common third party.
// Used by the trackers list filter to translate a CommonThirdParty GID
// into a `common_tracker_pattern_id = ANY(...)` constraint without
// JOINing across entity tables in coredata.
func (s *Service) LoadCommonTrackerPatternIDsByCommonThirdPartyID(
ctx context.Context,
commonThirdPartyID gid.GID,
) ([]gid.GID, error) {
var ids []gid.GID
err := s.pg.WithConn(
ctx,
func(ctx context.Context, conn pg.Querier) error {
var (
patterns coredata.CommonTrackerPatterns
err error
)
ids, err = patterns.LoadIDsByCommonThirdPartyID(ctx, conn, commonThirdPartyID)
if err != nil {
return fmt.Errorf("cannot load common tracker pattern ids: %w", err)
}
return nil
},
)
if err != nil {
return nil, err
}
return ids, nil
}
// LoadDistinctThirdPartyIDsByCookieBannerID returns the distinct
// org-scoped third-party IDs referenced by tracker patterns of the
// banner. The companion