Fix sqlite history not loading when maxHistory is -1

Fixes #2545
This commit is contained in:
Pavel Djundik 2018-06-11 14:08:05 +03:00
parent 12cd1b2614
commit ea00587c00

View File

@ -125,14 +125,17 @@ class MessageStorage {
* @param Chan channel - Channel object for which to load messages for * @param Chan channel - Channel object for which to load messages for
*/ */
getMessages(network, channel) { getMessages(network, channel) {
if (!this.isEnabled || Helper.config.maxHistory < 1) { if (!this.isEnabled || Helper.config.maxHistory === 0) {
return Promise.resolve([]); 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) => { return new Promise((resolve, reject) => {
this.database.parallelize(() => this.database.all( this.database.parallelize(() => this.database.all(
"SELECT msg, type, time FROM messages WHERE network = ? AND channel = ? ORDER BY time DESC LIMIT ?", "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) => { (err, rows) => {
if (err) { if (err) {
return reject(err); return reject(err);