I’m trying to create a script which finds how many friends a part you are from any other user, using a depth-first-search algorithm. (It is the most efficient method I’m aware of at the moment)
But due to the fact it requires so many :GetFriendsAsync() requests, I’m getting many HTTP 429 (Too Many Requests) errors, which is slowing down my searches to be unreasonably long.
I don’t know how I could decrease the number of requests I’m doing per search without having to use a system which saves and occasionally updates friend data (using datastores), because I want it to be up to date.
I’ve implemented a server cache (which saves all async outputs on a list if its used later in the server) but it doesn’t really seem to help. Are there any HTTPS servers I could use that would be significantly faster? Or any way to batch my async requests? Because I am at a loss here.
Here is a part of my code for fetching friend data for reference;
local function GetPlayerFriendList(player_id)
-- Check cache first
if Friend_List_Cache[player_id] then
return Friend_List_Cache[player_id]
end
local friendslist, err
for attempt = 1, 3 do -- Retry up to 3 times
local success
success, err = pcall(function()
friendslist = Players:GetFriendsAsync(player_id)
end)
if success then break end
task.wait(attempt * 0.2) -- Exponential backoff
end
if not friendslist then
return nil, err
end
local friends = {}
for item, _pageNo in iterPageItems(friendslist) do
table.insert(friends, item)
end
-- Cache the result
Friend_List_Cache[player_id] = friends
return friends, nil
end