Add coredata batch loaders for tracker third parties
Surface the third-party links carried by tracker patterns (org-scoped
ThirdParty via third_party_id, or global CommonThirdParty via
common_tracker_pattern_id) requires three new batch loaders and two
filter dimensions, all kept inside their owning entity tables to honour
the no-cross-entity-JOIN rule.
* CommonTrackerPatterns gains LoadByIDs and the ID-only
LoadIDsByCommonThirdPartyID helper, which lets callers translate a
common third party into a set of common_tracker_pattern_id values
without ever JOINing against tracker_patterns.
* CommonThirdParties gains LoadByIDs.
* TrackerPatterns gains LoadDistinctThirdPartyIDsByCookieBannerID and
LoadDistinctCommonTrackerPatternIDsByCookieBannerID, used by the
upcoming CookieBanner.linkedThirdParties resolver to enumerate the
third parties referenced in a banner.
* TrackerPatternFilter gains thirdPartyID and commonTrackerPatternIDs
filter dimensions; the GraphQL layer will dispatch a single
thirdPartyId argument to the right one based on the GID entity-type
prefix.
Service-layer wrappers (cookiebanner.GetCommonTrackerPatternsByIDs,
cookiebanner.LoadCommonTrackerPatternIDsByCommonThirdPartyID,
cookiebanner.LoadDistinctThirdPartyIDsByCookieBannerID,
cookiebanner.LoadDistinctCommonTrackerPatternIDsByCookieBannerID, and
thirdparty.GetCommonThirdPartiesByIDs) expose the new loaders to the
console resolvers and dataloaders that follow.
Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -2709,6 +2709,128 @@ func (s *Service) CountTrackerPatternsForBanner(
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetCommonTrackerPatternsByIDs(
|
||||
ctx context.Context,
|
||||
ids ...gid.GID,
|
||||
) (coredata.CommonTrackerPatterns, error) {
|
||||
var patterns coredata.CommonTrackerPatterns
|
||||
|
||||
err := s.pg.WithConn(
|
||||
ctx,
|
||||
func(ctx context.Context, conn pg.Querier) error {
|
||||
if err := patterns.LoadByIDs(ctx, conn, ids); err != nil {
|
||||
return fmt.Errorf("cannot load common tracker patterns by ids: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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
|
||||
// LoadDistinctCommonTrackerPatternIDsByCookieBannerID covers the
|
||||
// indirect mapping through common_tracker_patterns.
|
||||
func (s *Service) LoadDistinctThirdPartyIDsByCookieBannerID(
|
||||
ctx context.Context,
|
||||
scope coredata.Scoper,
|
||||
cookieBannerID 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.TrackerPatterns
|
||||
err error
|
||||
)
|
||||
|
||||
ids, err = patterns.LoadDistinctThirdPartyIDsByCookieBannerID(ctx, conn, scope, cookieBannerID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load distinct third party ids: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (s *Service) LoadDistinctCommonTrackerPatternIDsByCookieBannerID(
|
||||
ctx context.Context,
|
||||
scope coredata.Scoper,
|
||||
cookieBannerID 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.TrackerPatterns
|
||||
err error
|
||||
)
|
||||
|
||||
ids, err = patterns.LoadDistinctCommonTrackerPatternIDsByCookieBannerID(ctx, conn, scope, cookieBannerID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load distinct common tracker pattern ids: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (s *Service) CountDetectedTrackersByPatternID(
|
||||
ctx context.Context,
|
||||
scope coredata.Scoper,
|
||||
|
||||
Reference in New Issue
Block a user