Better handle large numbers of messages in cache on startup

This commit is contained in:
Scott Nonnenberg
2018-09-28 15:51:26 -07:00
parent 102c2717cb
commit 2cfbfe477a
5 changed files with 56 additions and 21 deletions

View File

@@ -42,6 +42,7 @@ module.exports = {
getNextExpiringMessage,
getMessagesByConversation,
getUnprocessedCount,
getAllUnprocessed,
saveUnprocessed,
getUnprocessedById,
@@ -962,6 +963,16 @@ async function getUnprocessedById(id) {
return jsonToObject(row.json);
}
async function getUnprocessedCount() {
const row = await db.get('SELECT count(*) from unprocessed;');
if (!row) {
throw new Error('getMessageCount: Unable to get count of unprocessed');
}
return row['count(*)'];
}
async function getAllUnprocessed() {
const rows = await db.all(
'SELECT json FROM unprocessed ORDER BY timestamp ASC;'