Solved [HELP] MySQL Constant Update

Discussion in 'Spigot Plugin Development' started by DragonLord__, Jan 31, 2020.

Thread Status:
Not open for further replies.
  1. I want to ask something.
    So when player gets muted, number of seconds is stored in mysql.
    So, the only way this blind kid sees to update db is:
    PreparedStatement sql = getConnection().prepareStatement("UPDATE Timer SET Time = Time - 1 WHERE Time > 0"); //This is just a test I ran
    This whole thing runs from onEnable() and this thing repeats every second
    I know that updating sql every second is bad, but I am as I said blind. So help me
  2. Maybe store the seconds left on enable into a hashmap or even better use currentTimeMillis
  3. Don't store the amount of time left in the database, just store when it should end. When you fetch from the database, cache it somewhere like a Map and remove it when it isn't needed.
  4. It's better if you cache the said data in your program and update it every once in a while, if you do it that way, be sure to update the data onDisable().
  5. I actually always forget that MySQL has DateTime option.......... This is testing mute plugin, is it bad if I fetch data every time muted player tries to use chat?
  6. I'd suggest you only use the database for loading data and saving data on server starts/stops/restarts and just use that cached data to handle your mutes until you use your current data to update the database.
  7. Yes. That would be something that you can load on player join and keep in-memory until the player leaves.
    And what if the server crashes? That data will be stuck on whatever it was the last time that the server saved and stopped. You can use a boolean flag, i.e. "dirty", to determine if data needs to be saved or not. This "dirty" data should be saved at intervals rather than immediately as the change occurs, then marked as clean (dirty = false) when the database is updated..
  8. Thanks for suggestion
Thread Status:
Not open for further replies.