Add some more sanity checks to cut down on database query spam

This commit is contained in:
zontreck 2024-04-25 02:15:31 -07:00
parent f54faa6f9e
commit aa6cb0e367
3 changed files with 20 additions and 1 deletions

View file

@ -53,7 +53,7 @@ mod_name=Zontreck's Library Mod
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3
# The mod version. See https://semver.org/
mod_version=1201.13.042524.0151
mod_version=1201.13.042524.0215
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -25,6 +25,11 @@ public abstract class BlockRestoreQueue
private final BlockRestoreRunner RUNNER;
private ScheduledFuture<?> RUNNING_TASK;
/**
* When in database mode, this flag will be checked by the Restore Runner so a database call is not made unnecessarily.
*/
private boolean hasBlocks = true;
public BlockRestoreQueue()
{
RUNNER = new BlockRestoreRunner(this);
@ -74,6 +79,7 @@ public abstract class BlockRestoreQueue
{
databaseUpdate(block);
notifyDirtyQueue(true);
hasBlocks=true;
return;
}
BLOCK_QUEUE.add(block);
@ -178,6 +184,16 @@ public abstract class BlockRestoreQueue
*/
public abstract boolean sorted();
/**
* Whether the queue has blocks or not
* @return
*/
public boolean hasBlocks()
{
if(usesDatabase()) return hasBlocks;
else return getQueuedBlocks() != 0;
}
/**
* Clears the entire queue, discarding the saved blocks permanently.
*/

View file

@ -25,6 +25,9 @@ public class BlockRestoreRunner implements Runnable
public void run() {
if(queue.getQueuedBlocks() == 0 && !queue.usesDatabase()) return; // We'll be queued back up later
if(!queue.hasBlocks())
return;
PrimitiveBlock prim = queue.getNextBlock();
if(prim == null)return; // No more blocks.