sqlite: use serialize_fetchall in getMessages
This commit is contained in:
parent
cc3302e874
commit
ee8223c200
@ -168,7 +168,7 @@ class SqliteMessageStorage implements ISqliteMessageStorage {
|
||||
* @param network Network - Network object where the channel is
|
||||
* @param channel Channel - Channel object for which to load messages for
|
||||
*/
|
||||
getMessages(network: Network, channel: Channel) {
|
||||
async getMessages(network: Network, channel: Channel): Promise<Message[]> {
|
||||
if (!this.isEnabled || Config.values.maxHistory === 0) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
@ -176,18 +176,14 @@ class SqliteMessageStorage implements ISqliteMessageStorage {
|
||||
// If unlimited history is specified, load 100k messages
|
||||
const limit = Config.values.maxHistory < 0 ? 100000 : Config.values.maxHistory;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.database.serialize(() =>
|
||||
this.database.all(
|
||||
const rows = await this.serialize_fetchall(
|
||||
"SELECT msg, type, time FROM messages WHERE network = ? AND channel = ? ORDER BY time DESC LIMIT ?",
|
||||
[network.uuid, channel.name.toLowerCase(), limit],
|
||||
(err, rows) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
network.uuid,
|
||||
channel.name.toLowerCase(),
|
||||
limit
|
||||
);
|
||||
|
||||
resolve(
|
||||
rows.reverse().map((row) => {
|
||||
return rows.reverse().map((row: any) => {
|
||||
const msg = JSON.parse(row.msg);
|
||||
msg.time = row.time;
|
||||
msg.type = row.type;
|
||||
@ -196,12 +192,7 @@ class SqliteMessageStorage implements ISqliteMessageStorage {
|
||||
newMsg.id = this.client.idMsg++;
|
||||
|
||||
return newMsg;
|
||||
})
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}) as Promise<Message[]>;
|
||||
}) as Message[];
|
||||
}
|
||||
|
||||
search(query: SearchQuery): Promise<SearchResponse> {
|
||||
|
Loading…
Reference in New Issue
Block a user