mirror of
1
Fork 0

Compile filter keyword regexps when touched through PutFilter or UpdateFilter (#2951)

Followup to #2903
This commit is contained in:
Vyr Cossont 2024-06-04 02:33:39 -07:00 committed by GitHub
parent f17dd62ff5
commit 45fe295caa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 0 deletions

View File

@ -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.
@ -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.