Add some more sanity checks to cut down on database query spam
This commit is contained in:
parent
f54faa6f9e
commit
aa6cb0e367
3 changed files with 20 additions and 1 deletions
|
@ -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.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=GPLv3
|
mod_license=GPLv3
|
||||||
# The mod version. See https://semver.org/
|
# 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.
|
# 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.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|
|
@ -25,6 +25,11 @@ public abstract class BlockRestoreQueue
|
||||||
private final BlockRestoreRunner RUNNER;
|
private final BlockRestoreRunner RUNNER;
|
||||||
private ScheduledFuture<?> RUNNING_TASK;
|
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()
|
public BlockRestoreQueue()
|
||||||
{
|
{
|
||||||
RUNNER = new BlockRestoreRunner(this);
|
RUNNER = new BlockRestoreRunner(this);
|
||||||
|
@ -74,6 +79,7 @@ public abstract class BlockRestoreQueue
|
||||||
{
|
{
|
||||||
databaseUpdate(block);
|
databaseUpdate(block);
|
||||||
notifyDirtyQueue(true);
|
notifyDirtyQueue(true);
|
||||||
|
hasBlocks=true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BLOCK_QUEUE.add(block);
|
BLOCK_QUEUE.add(block);
|
||||||
|
@ -178,6 +184,16 @@ public abstract class BlockRestoreQueue
|
||||||
*/
|
*/
|
||||||
public abstract boolean sorted();
|
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.
|
* Clears the entire queue, discarding the saved blocks permanently.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,6 +25,9 @@ public class BlockRestoreRunner implements Runnable
|
||||||
public void run() {
|
public void run() {
|
||||||
if(queue.getQueuedBlocks() == 0 && !queue.usesDatabase()) return; // We'll be queued back up later
|
if(queue.getQueuedBlocks() == 0 && !queue.usesDatabase()) return; // We'll be queued back up later
|
||||||
|
|
||||||
|
if(!queue.hasBlocks())
|
||||||
|
return;
|
||||||
|
|
||||||
PrimitiveBlock prim = queue.getNextBlock();
|
PrimitiveBlock prim = queue.getNextBlock();
|
||||||
if(prim == null)return; // No more blocks.
|
if(prim == null)return; // No more blocks.
|
||||||
|
|
||||||
|
|
Reference in a new issue