-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if the comparison target is nil, comparison with lower("accounts"."domain")
is required to use the index.
442fc68
to
226e3e8
Compare
Fabricate(:account, domain: 'にゃん', username: 'username') | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, this test was wrong. When saving the account without validating the username, an error occurred due to unique constraint of DB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.