From ea00587c00150499b8420b449bcf3409c214d4b8 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 11 Jun 2018 14:08:05 +0300 Subject: [PATCH] Fix sqlite history not loading when maxHistory is -1 Fixes #2545 --- src/plugins/messageStorage/sqlite.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/plugins/messageStorage/sqlite.js b/src/plugins/messageStorage/sqlite.js index 2b939179..0db36b54 100644 --- a/src/plugins/messageStorage/sqlite.js +++ b/src/plugins/messageStorage/sqlite.js @@ -125,14 +125,17 @@ class MessageStorage { * @param Chan channel - Channel object for which to load messages for */ getMessages(network, channel) { - if (!this.isEnabled || Helper.config.maxHistory < 1) { + if (!this.isEnabled || Helper.config.maxHistory === 0) { return Promise.resolve([]); } + // If unlimited history is specified, load 100k messages + const limit = Helper.config.maxHistory < 0 ? 100000 : Helper.config.maxHistory; + return new Promise((resolve, reject) => { this.database.parallelize(() => this.database.all( "SELECT msg, type, time FROM messages WHERE network = ? AND channel = ? ORDER BY time DESC LIMIT ?", - [network.uuid, channel.name.toLowerCase(), Helper.config.maxHistory], + [network.uuid, channel.name.toLowerCase(), limit], (err, rows) => { if (err) { return reject(err);