= Updated db upkeep frequency

This commit is contained in:
Matthew Cech
2019-05-24 04:01:56 -07:00
parent ad6def8e93
commit 0ca4160d7b
+10 -1
View File
@@ -1,5 +1,7 @@
package main; package main;
import java.util.concurrent.atomic.AtomicInteger;
import core.DatabaseManager; import core.DatabaseManager;
import core.LocCommands; import core.LocCommands;
import core.LocStrings; import core.LocStrings;
@@ -79,13 +81,20 @@ public class Superintendent
return true; return true;
} }
private static final Integer delayTimerReset = 5;
private static AtomicInteger delayTimerCurrent = new AtomicInteger(delayTimerReset);
// This is for stuff that we need to do on a regular basis, but don't // This is for stuff that we need to do on a regular basis, but don't
// necessarily want running at all points in time. // necessarily want running at all points in time.
// Happens just after the command / plugin runs. // Happens just after the command / plugin runs.
public static boolean PerCommandUpkeepPost(JDA bot, DatabaseManager databaseManager) public static boolean PerCommandUpkeepPost(JDA bot, DatabaseManager databaseManager)
{ {
// Upkeep database // Upkeep database lazily on occasion
if(delayTimerCurrent.decrementAndGet() < 0)
{
databaseManager.Upkeep(); databaseManager.Upkeep();
delayTimerCurrent.set(delayTimerReset);
}
// Update command-specific // Update command-specific
RPManager.Upkeep(bot); RPManager.Upkeep(bot);