Merge pull request #2546 from thelounge/xpaw/fix-2545

Fix sqlite history not loading when maxHistory is -1
This commit is contained in:
Jérémie Astori 2018-06-11 09:13:29 -04:00 committed by GitHub
commit eff7618f79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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);