Skip to content

Commit

Permalink
Compile filter keyword regexps when touched through PutFilter or Upda…
Browse files Browse the repository at this point in the history
…teFilter (#2951)

Followup to #2903
  • Loading branch information
VyrCossont authored Jun 4, 2024
1 parent f17dd62 commit 45fe295
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/db/bundb/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ func (f *filterDB) populateFilter(ctx context.Context, filter *gtsmodel.Filter)
}

func (f *filterDB) PutFilter(ctx context.Context, filter *gtsmodel.Filter) error {
// Pre-compile filter keyword regular expressions.
for _, filterKeyword := range filter.Keywords {
if err := filterKeyword.Compile(); err != nil {
return gtserror.Newf("error compiling filter keyword regex: %w", err)
}
}

// Update database.
if err := f.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
if _, err := tx.
Expand Down Expand Up @@ -225,6 +232,13 @@ func (f *filterDB) UpdateFilter(
}
}

// Pre-compile filter keyword regular expressions.
for _, filterKeyword := range filter.Keywords {
if err := filterKeyword.Compile(); err != nil {
return gtserror.Newf("error compiling filter keyword regex: %w", err)
}
}

// Update database.
if err := f.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
if _, err := tx.
Expand Down

0 comments on commit 45fe295

Please sign in to comment.