Search account domain in lowercase#13016
Conversation
| else | ||
| Account.where(Account.arel_table[:domain].lower.eq domain.to_s.downcase) | ||
| end | ||
| Account.where(Account.arel_table[:domain].lower.eq(domain.nil? ? nil : domain.to_s.downcase)) |
There was a problem hiding this comment.
Even if the comparison target is nil, comparison with lower("accounts"."domain") is required to use the index.
442fc68 to
226e3e8
Compare
| account = Fabricate.build(:account, domain: 'xn--r9j5b5b', username: 'Username') | ||
| account.valid? | ||
| expect(account).not_to model_have_error_on_field(:username) | ||
| expect(account).to model_have_error_on_field(:username) |
There was a problem hiding this comment.
In fact, this test was wrong. When saving the account without validating the username, an error occurred due to unique constraint of DB.
ClearlyClaire
left a comment
There was a problem hiding this comment.
Seems ok with current practices, but technically, the local part of acct URIs is supposed to be case-sensitive.
I don't think that's true? |
|
@Gargron the specs say that the local part of acct: URIs are supposed to be case-sensitive. It's just that in Mastodon we explicitly decided to go against that, to accommodate with people changing the casing of already-existing accounts manually, iirc EDIT: but anyway, we already make that assumption in various places, so this PR shouldn't break anything that wasn't already broken |
* Search account domain in lowercase * fix rubocop error * fix spec/models/account_spec.rb
…query Search account domain in lowercase (mastodon#13016)
I noticed that the validation query before saving the remote account did not work with the index.
Since the index of the account is as follows, it is necessary to compare it with
lower("accounts"." username")andlower("accounts"."domain")to use index.As a result of the fix, the index is now used correctly.
Also, the remote account is validated with
case_sensitive: true, but the actual unique index is not case-sensitive, so this was also fixed.