06.01.2018, 15:59
I was just about to create a timer to update all online players' online time in a MySQL table every 5 minutes, but then I thought... would a MySQL event be better? Something like:
Or to decrease the amount of load, even:
Would it be slow/inefficient for MySQL to search through potentially thousands of rows for online players?
Or perhaps I could have a separate table that adds a row for users when they come online in-game, and deletes the row when they disconnect, and have the event update if their ID exists in that table? What do you think?
Edit: obviously, when a player disconnects their online time will be saved from the gamemode.
Code:
CREATE EVENT update_time ON SCHEDULE EVERY 1 SECOND DO UPDATE users SET onlinetime = onlinetime + 1 WHERE online = 1;
Code:
CREATE EVENT update_time ON SCHEDULE EVERY 60 SECOND DO UPDATE users SET onlinetime = onlinetime + 60 WHERE online = 1;
Or perhaps I could have a separate table that adds a row for users when they come online in-game, and deletes the row when they disconnect, and have the event update if their ID exists in that table? What do you think?
Edit: obviously, when a player disconnects their online time will be saved from the gamemode.