mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 14:22:25 -05:00 
			
		
		
		
	Compile filter keyword regexps when touched through PutFilter or UpdateFilter (#2951)
Followup to #2903
This commit is contained in:
		
					parent
					
						
							
								f17dd62ff5
							
						
					
				
			
			
				commit
				
					
						45fe295caa
					
				
			
		
					 1 changed files with 14 additions and 0 deletions
				
			
		|  | @ -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 { | 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. | 	// Update database. | ||||||
| 	if err := f.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { | 	if err := f.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { | ||||||
| 		if _, err := tx. | 		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. | 	// Update database. | ||||||
| 	if err := f.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { | 	if err := f.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { | ||||||
| 		if _, err := tx. | 		if _, err := tx. | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue