How do I make sure HashMap:AdvanceToNextPageAsync() does not throttle every minute?

I recently re-coded my server browser to use a MemoryStore HashMap to keep track of a server’s status, details, and the players in the server. The problem is, I don’t understand why API requests with this call are significantly higher than my other calls.

For some context:
My server browser place is a 1-player server. The function that contains this call only fires upon the player entering the server, and every 30 seconds after the server is opened.

My game usually gets around 10 active players at a given moment, where about 1-3 of them are in the server browser place. In theory, I should be getting around 20 calls per minute but I’ve reached numbers over 1000.

Here’s the API Request Unit graph captured from the Analytics tab.

Here’s the code that contains the call in question:

function BrowserService:FetchAllServerDetails()
	local ServerDetailsInHashMap 
	local success, err = pcall(function()
		ServerDetailsInHashMap = ServerDetailsHash:ListItemsAsync(200)
	end)
	
	if not success then
		warn("[BrowserService]: There was an error fetching server details: " ..err)
		print("Trying again in 5 seconds.")
		task.wait(5)
		BrowserService:FetchAllServerDetails()
		return
	end
	
	if not ServerDetailsInHashMap then
		warn("[BrowserService]: ServerDetailsInHashMap is nil! Not listing anything.")
		return
	end
		
	while not ServerDetailsInHashMap.IsFinished do
		local ServerDetailsPage = ServerDetailsInHashMap:GetCurrentPage()
		for _, ServerDetailsEntry in pairs(ServerDetailsPage) do
			local ServerDetails = ServerDetailsEntry.value
			BrowserService:UpdateServer(ServerDetails)
		end
			
		if not ServerDetailsInHashMap.IsFinished then
			ServerDetailsInHashMap:AdvanceToNextPageAsync() -- I added a pcall after copy-pasting my code
		end
	end
end

Have you tried reproducing the issue yourself and seeing what the error returns?

Here’s a screenshot of the error log that threw an error due to throttling of the HashMap:


Note: The “Using da async” that the console outputs prints just before the AdvanceToNextPageAsync() is called.

The issue can be reproduced if the user simply joins the server, as the function is called when the player joins the server.

Found the problem. For future reference go check out this post:

It’s better to use SortedMaps instead :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.