From a2c090583beed816cdb557800a9dd7c2b649f5e9 Mon Sep 17 00:00:00 2001 From: topboy Date: Fri, 13 Sep 2024 19:44:36 -0500 Subject: [PATCH 1/2] patch interleaving batches --- src/commands/handler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/handler.js b/src/commands/handler.js index 2cb46aff..c449e0a7 100644 --- a/src/commands/handler.js +++ b/src/commands/handler.js @@ -38,7 +38,7 @@ module.exports = class IrcCommandHandler extends EventEmitter { // Batched commands will be collected and executed as a transaction const batch_id = irc_command.getTag('batch'); - if (batch_id) { + if (batch_id && !(irc_command.command === 'BATCH' && irc_command.params[0].charAt(0) === '+')) { const cache_key = 'batch.' + batch_id; if (this.hasCache(cache_key)) { const cache = this.cache(cache_key); From 8b0f58f415b30d286ffa31e7ff1e840d17832674 Mon Sep 17 00:00:00 2001 From: topboy Date: Sat, 21 Sep 2024 09:46:22 -0500 Subject: [PATCH 2/2] ok actually fix interleaving batches --- src/commands/handler.js | 12 ++++++++++-- src/commands/handlers/misc.js | 11 ++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/commands/handler.js b/src/commands/handler.js index c449e0a7..f3f0f84d 100644 --- a/src/commands/handler.js +++ b/src/commands/handler.js @@ -38,16 +38,24 @@ module.exports = class IrcCommandHandler extends EventEmitter { // Batched commands will be collected and executed as a transaction const batch_id = irc_command.getTag('batch'); - if (batch_id && !(irc_command.command === 'BATCH' && irc_command.params[0].charAt(0) === '+')) { + if (batch_id) { const cache_key = 'batch.' + batch_id; if (this.hasCache(cache_key)) { - const cache = this.cache(cache_key); + let cache = this.cache(cache_key); cache.commands.push(irc_command); + while (cache?.tags?.batch) { + cache = this.cache('batch.' + cache.tags.batch); + cache.commands.push(irc_command); + } } else { // If we don't have this batch ID in cache, it either means that the // server hasn't sent the starting batch command or that the server // has already sent the end batch command. } + // start interleaving batches anyway + if (irc_command.command === 'BATCH' && irc_command.params[0].charAt(0) === '+') { + this.executeCommand(irc_command); + } } else { this.executeCommand(irc_command); } diff --git a/src/commands/handlers/misc.js b/src/commands/handlers/misc.js index 2fcef18a..dd9c8645 100644 --- a/src/commands/handlers/misc.js +++ b/src/commands/handlers/misc.js @@ -310,11 +310,13 @@ const handlers = { } if (batch_start) { + // in case of an interleaving batch + if (handler.hasCache(cache_key)) return; const cache = handler.cache(cache_key); cache.commands = []; cache.type = command.params[1]; cache.params = command.params.slice(2); - + cache.tags = command.tags; return; } @@ -330,7 +332,8 @@ const handlers = { id: batch_id, type: cache.type, params: cache.params, - commands: cache.commands + commands: cache.commands, + tags: cache.tags, }; // Destroy the cache object before executing each command. If one @@ -340,10 +343,12 @@ const handlers = { handler.emit('batch start', emit_obj); handler.emit('batch start ' + emit_obj.type, emit_obj); emit_obj.commands.forEach((c) => { + if (c.getTag('batch') !== batch_id) return; c.batch = { id: batch_id, type: cache.type, - params: cache.params + params: cache.params, + tags: cache.tags, }; handler.executeCommand(c); });