Followup to a8fbb19e

Followup to a8fbb19e

Correct edge condition where no available names are found

  • increase search space
  • search for 10 extra names
diff --git a/lib/user_name_suggester.rb b/lib/user_name_suggester.rb
index 12dd7df..bea9de6 100644
--- a/lib/user_name_suggester.rb
+++ b/lib/user_name_suggester.rb
@@ -40,7 +40,8 @@ module UserNameSuggester
         SQL
 
         if count > 0
-          available = DB.query_single(<<~SQL, count: count, name: normalized).first
+          # increasing the search space a bit to allow for some extra noise
+          available = DB.query_single(<<~SQL, count: count + 10, name: normalized).first
             WITH numbers AS (SELECT generate_series(1, :count) AS n)
 
             SELECT n FROM numbers
@@ -51,7 +52,8 @@ module UserNameSuggester
           SQL
 
           # we start at 1
-          offset = available - 1
+          offset = available.to_i - 1
+          offset = 0 if offset < 0
         else
           offset = 0
         end

GitHub sha: cabc2038