From f5c342c78596a474323d8de5f6cbe241cb30022a Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sun, 19 Feb 2023 14:26:52 -0500 Subject: [PATCH] Attempt #3 to fix chat filter and missing index --- gui/preload-chat.js | 59 ++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 152e41e5..ef02140f 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -1502,34 +1502,49 @@ function updateAllChat(clear){ //document.getElementById("list-tab").childNodes.remove(); //document.getElementById("nav-tab-content").childrenNodes.remove(); } - - db.find({ - selector: { - $and: [{timestamp: {$exists:true}}, - {$or:chatFilter}], - //$or: chatFilter + //Ensure we create an index before running db.find + //We can't rely on the default index existing before we get here...... :'( + db.createIndex({ + index: { + fields: [ + {"timestamp":"asc"}, + ], }, - sort: [ - { - timestamp: "asc", - }, - ], }) - .then(async function (result) { - // handle result async - if (typeof result !== "undefined") { - for (const item of result.docs) + .then(function (result) { + // handle result + db.find({ + selector: { + $and: [{timestamp: {$exists:true}}, + {$or:chatFilter}], + //$or: chatFilter + }, + sort: [ { - //await otherwise history will not be in chronological order - await db.get(item._id, { - attachments: true, - }).then(function (item_with_attachments) { - update_chat(item_with_attachments); - }); + timestamp: "asc", + }, + ], + }) + .then(async function (result) { + // handle result async + if (typeof result !== "undefined") { + for (const item of result.docs) + { + //await otherwise history will not be in chronological order + await db.get(item._id, { + attachments: true, + }).then(function (item_with_attachments) { + update_chat(item_with_attachments); + }); + } } - } + }) + .catch(function (err) { + console.log(err); + }); }) .catch(function (err) { console.log(err); }); + }