Scope reset-trackers by keyword and report progress

The reset-trackers operator command reset every uncategorised,
non-excluded pattern of a banner and printed only a single summary
line once the transaction committed, giving no feedback during long
rebuilds.

Add a --keyword flag that scopes both the glob decomposition and the
mapping reset to patterns whose pattern or display name contains the
substring. The match lives in a new TrackerPatternFilter.WithPatternKeyword
field so it runs in SQL and is shared by the glob load and the
ResetAndRequestMappingByCookieCategoryID update, keeping the two in
lockstep. The banner-wide pattern-analysis re-arm is left unscoped.

Thread an optional progress callback through ResetBannerTrackers so the
command streams per-phase updates (category load, per-glob decomposition,
mapping reset, analysis re-arm) as the work runs.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-06-09 19:40:16 +02:00
parent 5415b2d438
commit faca86a022
5 changed files with 95 additions and 10 deletions

View File

@@ -27,6 +27,7 @@ import (
func newCmdResetTrackers(f *cmdutil.Factory) *cobra.Command {
var (
flagMappingOnly bool
flagKeyword string
flagDryRun bool
flagYes bool
)
@@ -38,11 +39,14 @@ func newCmdResetTrackers(f *cmdutil.Factory) *cobra.Command {
"non-excluded patterns it clears catalog/vendor links, rebuilds the raw exact " +
"patterns from detected_trackers (decomposing derived globs), and re-arms the " +
"pattern-analysis and mapping workers. User-categorised and excluded patterns are " +
"preserved. With --mapping-only it skips the rebuild and only re-arms mapping.",
"preserved. With --mapping-only it skips the rebuild and only re-arms mapping. " +
"With --keyword the rebuild and mapping reset are scoped to patterns whose pattern " +
"or display name contains the substring.",
Args: cobra.ExactArgs(1),
}
cmd.Flags().BoolVar(&flagMappingOnly, "mapping-only", false, "Only re-arm mapping (skip the detection rebuild and analysis)")
cmd.Flags().StringVar(&flagKeyword, "keyword", "", "Only reset patterns whose pattern or display name contains this substring")
cmd.Flags().BoolVar(&flagDryRun, "dry-run", false, "Print the target banner without writing")
cmd.Flags().BoolVar(&flagYes, "yes", false, "Skip confirmation")
@@ -68,6 +72,12 @@ func newCmdResetTrackers(f *cmdutil.Factory) *cobra.Command {
mode = "mapping-only reset"
}
var keyword *string
if flagKeyword != "" {
keyword = &flagKeyword
mode = fmt.Sprintf("%s scoped to keyword %q", mode, flagKeyword)
}
if flagDryRun {
_, _ = fmt.Fprintf(out, "Would run %s on banner %s.\n", mode, bannerID.String())
return nil
@@ -77,7 +87,13 @@ func newCmdResetTrackers(f *cmdutil.Factory) *cobra.Command {
return fmt.Errorf("about to run %s on banner %s; pass --yes to proceed or --dry-run to preview", mode, bannerID.String())
}
result, err := cookiebanner.ResetBannerTrackers(ctx, pgClient, scope, bannerID, flagMappingOnly)
_, _ = fmt.Fprintf(out, "Running %s on banner %s.\n", mode, bannerID.String())
progress := func(message string) {
_, _ = fmt.Fprintf(out, " %s\n", message)
}
result, err := cookiebanner.ResetBannerTrackers(ctx, pgClient, scope, bannerID, flagMappingOnly, keyword, progress)
if err != nil {
return fmt.Errorf("cannot reset banner %s: %w", bannerID, err)
}