Timed OrderedDataStores and Performance

Hi there, I’m currently working on the creation of a global leaderboard system in which players will be able to view their statistics on an all time, daily, weekly and monthly basis. The system is essentially complete, although I have a concern about the performance of data collection/saving.

function GetDatastoreNames()
	local DateTable = os.date("!*t", os.time())
	
	DailyName = DateTable.day.."/"..DateTable.month.."/"..DateTable.year
	WeeklyName = math.floor(DateTable.yday/7).."/"..DateTable.year
	MonthlyName = DateTable.month.."/"..DateTable.year
	
	DailyWins = game:GetService("DataStoreService"):GetOrderedDataStore("DailyWins_"..DailyName)
    WeeklyWins = game:GetService("DataStoreService"):GetOrderedDataStore("WeeklyWins_"..WeeklyName)
    MonthlyWins = game:GetService("DataStoreService"):GetOrderedDataStore("MonthlyWins_"..MonthlyName)
	
end

In the above code snippet I essentially have an OrderedDataStore which changes automatically depending on the current date, one for a daily, weekly and monthly basis whenever the function is called.

However, my concern is when an active server overlaps into a new day, week or month… currently I update the datastore names on each call for getting or saving data to ensure that I get the most up to date data. Is this not recommended? Should I instead refresh the names after a certain time limit?

What is the best way to ensure that the time is always up to date, without impacting performance as a result of all the calculations having to be made each time data is updated/fetched?

2 Likes

This is probably a better place to post your topic;
https://devforum.roblox.com/c/development-support/code-review

1 Like