I have a private instance user model method like below:-
def generate_authentication_token
loop do
token = Devise.friendly_token
break token unless self.class.unscoped.where(authentication_token: token).first
end
end
Let us assume that, no. of user record is 100 trillions. If I issue the above script and the token generated on each iteration matches with a record then, loop will iterate for 100 trillion times, same will happen with DBMS too for searching record. Is there any solution to make this problem fast, by reducing iteration and reducing db-hits (given that each iteration will give matching record). And seriously, sorry ! if the question makes no sense and let me know, I will delete ASAP. Thanks. Happy Coding.