From 2ef5fe831d753dafa50fddb134b7f0c89eb4d703 Mon Sep 17 00:00:00 2001
From: Andrii <andriyndev@gmail.com>
Date: Sun, 20 Oct 2024 00:05:18 +0300
Subject: [PATCH] Don't reset timer when adding messages to batch

---
 inventory.lua | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/inventory.lua b/inventory.lua
index 9dec8d1..8cbd36f 100644
--- a/inventory.lua
+++ b/inventory.lua
@@ -79,13 +79,10 @@ local function send_message(pos, action, stack, from_slot, to_slot, side)
 		if cur_time - prev_time < 1000000 * interval_to_batch or batches[pos_hash] then
 			batches[pos_hash] = batches[pos_hash] or { messages = {} }
 			table.insert(batches[pos_hash].messages, msg)
-			if batches[pos_hash].timer then
-				batches[pos_hash].timer:cancel()
-			end
 			if #batches[pos_hash].messages >= max_messages_in_batch then
 				-- Send the batch immediately if it's full
 				send_and_clear_batch(pos, channel)
-			else
+			elseif not batches[pos_hash].timer then
 				batches[pos_hash].timer = minetest.after(interval_to_batch, send_batch_on_timer, pos)
 			end