Skip to content

Commit

Permalink
Fixed unnecessary database transactions when consumer is empty (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed May 11, 2024
1 parent 3b9d872 commit e61b8a4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/net/coreprotect/consumer/process/Process.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ protected static void processConsumer(int processId, boolean lastRun) {
int consumerDataSize = consumerData.size();
currentConsumerSize = consumerDataSize;

if (currentConsumerSize == 0) { // No data, skip processing
updateLockTable(statement, (lastRun ? 0 : 1));
statement.close();
Consumer.consumer_id.put(processId, new Integer[] { 0, 0 });
Consumer.isPaused = false;
return;
}

Database.beginTransaction(statement);
// Scan through usernames, ensure everything is loaded in memory.
for (Entry<Integer, String[]> entry : users.entrySet()) {
Expand Down Expand Up @@ -225,6 +233,7 @@ protected static void processConsumer(int processId, boolean lastRun) {
consumerData.remove(index);
}
currentConsumerSize = 0;
Consumer.consumer_id.put(processId, new Integer[] { 0, 0 });
Consumer.isPaused = false;
return;
}
Expand Down

0 comments on commit e61b8a4

Please sign in to comment.