Fix recurring memory leak in mentions

This commit is contained in:
sachaaaaa 2019-11-13 15:52:17 +11:00
parent 6611a10855
commit 2c1375e42a
4 changed files with 40 additions and 12 deletions

View File

@ -103,6 +103,7 @@ module.exports = {
getAllRssFeedConversations,
getAllPublicConversations,
getPublicConversationsByServer,
getPubkeysInPublicConversation,
getPubKeysWithFriendStatus,
getAllConversationIds,
getAllPrivateConversations,
@ -1740,6 +1741,19 @@ async function getPublicConversationsByServer(server) {
return map(rows, row => jsonToObject(row.json));
}
async function getPubkeysInPublicConversation(id) {
const rows = await db.all(
`SELECT DISTINCT source FROM messages WHERE
conversationId = $conversationId
ORDER BY id ASC;`,
{
$conversationId: id,
}
);
return map(rows, row => row.source);
}
async function getAllGroupsInvolvingId(id) {
const rows = await db.all(
`SELECT json FROM conversations WHERE

View File

@ -1,4 +1,4 @@
/* global window, setTimeout, IDBKeyRange */
/* global window, setTimeout, clearTimeout, IDBKeyRange */
const electron = require('electron');
@ -124,6 +124,7 @@ module.exports = {
getAllRssFeedConversations,
getAllPublicConversations,
getPublicConversationsByServer,
getPubkeysInPublicConversation,
savePublicServerToken,
getPublicServerTokenByServerUrl,
getAllGroupsInvolvingId,
@ -312,6 +313,11 @@ function _removeJob(id) {
return;
}
if (_jobs[id].timer) {
clearTimeout(_jobs[id].timer);
_jobs[id].timer = null;
}
delete _jobs[id];
if (_shutdownCallback) {
@ -363,7 +369,7 @@ function makeChannel(fnName) {
args: _DEBUG ? args : null,
});
setTimeout(
_jobs[jobId].timer = setTimeout(
() =>
reject(new Error(`SQL channel job ${jobId} (${fnName}) timed out`)),
DATABASE_UPDATE_TIMEOUT
@ -764,6 +770,10 @@ async function getAllPrivateConversations({ ConversationCollection }) {
return collection;
}
async function getPubkeysInPublicConversation(id) {
return channels.getPubkeysInPublicConversation(id);
}
async function savePublicServerToken(data) {
await channels.savePublicServerToken(data);
}

View File

@ -22,6 +22,7 @@ class LokiAppDotNetAPI extends EventEmitter {
this.ourKey = ourKey;
this.servers = [];
this.myPrivateKey = false;
this.allMembers = [];
}
async getPrivateKey() {
@ -785,8 +786,8 @@ class LokiPublicChannelAPI {
log.warn(`Error while polling for public chat messages: ${e}`);
}
if (this.running) {
setTimeout(() => {
this.timers.message = this.pollForMessages();
this.timers.message = setTimeout(() => {
this.pollForMessages();
}, PUBLICCHAT_MSG_POLL_EVERY);
}
}

View File

@ -341,16 +341,19 @@
this.selectMember = this.selectMember.bind(this);
const updateMemberList = async () => {
const maxToFetch = 1000;
const allMessages = await window.Signal.Data.getMessagesByConversation(
this.model.id,
{
limit: maxToFetch,
MessageCollection: Whisper.MessageCollection,
}
const allPubKeys = await window.Signal.Data.getPubkeysInPublicConversation(
this.model.id
);
const allMembers = allMessages.models.map(d => d.propsForMessage);
const allMembers = await Promise.all(
allPubKeys.map(async pubKey => ({
id: pubKey,
authorPhoneNumber: pubKey,
authorProfileName: await ConversationController.get(
pubKey
).getProfileName(),
}))
);
window.lokiPublicChatAPI.setListOfMembers(allMembers);
};