Add common catalog query layer and enricher service
Introduce an API-style data layer for the global common tracker pattern and common third party catalogs: typed filters, order fields, CursorKey, cursor-paginated Load and CountAll, plus by-id enrichment re-queue and a scoped reset/remap helper for a banner's tracker patterns. These reuse the same page.Cursor/filter/order types the GraphQL API consumes, so a future proboctl API can back them unchanged. Extract the common-pattern enrichment logic out of the worker into a CommonPatternEnricher service so it can run either from the background queue or synchronously over a known set of ids; the worker becomes a thin poller that delegates to it. Extract the LLM client and tracker-agents config wiring into pkg/agentsbuild so probod and other binaries build agents identically; probod now delegates to it. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -295,6 +295,99 @@ LIMIT @limit;
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// LoadAllByTrackerPatternID returns every detected tracker linked to the
|
||||
// pattern, with no pagination. It backs the banner-reset rebuild, which
|
||||
// recreates exact patterns from a glob's detections.
|
||||
func (dts *DetectedTrackers) LoadAllByTrackerPatternID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
scope Scoper,
|
||||
trackerPatternID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
cookie_banner_id,
|
||||
tracker_pattern_id,
|
||||
tracker_type,
|
||||
identifier,
|
||||
max_age_seconds,
|
||||
source,
|
||||
value_size,
|
||||
initiator_url,
|
||||
initiator_domain,
|
||||
last_detected_at,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
detected_trackers
|
||||
WHERE
|
||||
%s
|
||||
AND tracker_pattern_id = @tracker_pattern_id
|
||||
ORDER BY
|
||||
identifier ASC, id ASC
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"tracker_pattern_id": trackerPatternID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query detected trackers: %w", err)
|
||||
}
|
||||
|
||||
trackers, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[DetectedTracker])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect detected trackers: %w", err)
|
||||
}
|
||||
|
||||
*dts = trackers
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateTrackerPatternID repoints a single detected tracker at another
|
||||
// pattern. It is the per-row counterpart of RelinkByTrackerPatternID,
|
||||
// used by the banner-reset rebuild where each detection of a glob moves
|
||||
// to its own recreated exact pattern.
|
||||
func (dt *DetectedTracker) UpdateTrackerPatternID(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE detected_trackers
|
||||
SET
|
||||
tracker_pattern_id = @tracker_pattern_id,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": dt.ID,
|
||||
"tracker_pattern_id": dt.TrackerPatternID,
|
||||
"updated_at": time.Now(),
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
result, err := tx.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update detected tracker pattern: %w", err)
|
||||
}
|
||||
|
||||
if result.RowsAffected() == 0 {
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dts *DetectedTrackers) RelinkByTrackerPatternID(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
|
||||
Reference in New Issue
Block a user