View Single Post
Old 06/01/2018, 04:59 PM   #1
dicknyson
Banned
 
Join Date: Feb 2016
Location: 𝕪𝕠𝕦𝕥𝕦𝕓𝕖
Posts: 56
Reputation: 5
Default Saving online time with a MySQL event

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:

Code:
CREATE EVENT update_time ON SCHEDULE EVERY 1 SECOND DO
  UPDATE users SET onlinetime = onlinetime + 1 WHERE online = 1;
Or to decrease the amount of load, even:
Code:
CREATE EVENT update_time ON SCHEDULE EVERY 60 SECOND DO
  UPDATE users SET onlinetime = onlinetime + 60 WHERE online = 1;
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.
dicknyson is offline   Reply With Quote