FEATURE: allow a huge number of users to share common prefix

Previously username suggester would give up after 100 attempts at getting
a username and fallback to random string.

This amends the logic so we do all the work of figuring out a good username
in SQL and avoids a large amount of queries in cases where a lot of usernames
were used up.

This corrects an issue on sites with large numbers of anon users
This commit is contained in:
Sam Saffron
2019-05-16 17:15:03 +10:00
parent ea214b2b0c
commit a8fbb19e7c
2 changed files with 42 additions and 1 deletions

View File

@@ -10,6 +10,15 @@ describe UserNameSuggester do
SiteSetting.max_username_length = 15
end
it "keeps adding numbers to the username" do
Fabricate(:user, username: 'sam')
Fabricate(:user, username: 'sAm1')
Fabricate(:user, username: 'sam2')
Fabricate(:user, username: 'sam4')
expect(UserNameSuggester.suggest('saM')).to eq('saM3')
end
it "doesn't raise an error on nil username" do
expect(UserNameSuggester.suggest(nil)).to eq(nil)
end