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