Consolidate account scopes for LOWER (index using) username/domain queries (#30451)
		
	This commit is contained in:
		
					parent
					
						
							
								32c30bf0fd
							
						
					
				
			
			
				commit
				
					
						4a77e477ee
					
				
			
		
					 6 changed files with 14 additions and 48 deletions
				
			
		|  | @ -6,10 +6,7 @@ class UniqueUsernameValidator < ActiveModel::Validator | |||
|   def validate(account) | ||||
|     return if account.username.blank? | ||||
| 
 | ||||
|     normalized_username = account.username.downcase | ||||
|     normalized_domain = account.domain&.downcase | ||||
| 
 | ||||
|     scope = Account.where(Account.arel_table[:username].lower.eq normalized_username).where(Account.arel_table[:domain].lower.eq normalized_domain) | ||||
|     scope = Account.with_username(account.username).with_domain(account.domain) | ||||
|     scope = scope.where.not(id: account.id) if account.persisted? | ||||
| 
 | ||||
|     account.errors.add(:username, :taken) if scope.exists? | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue