diff --git a/api/models/Conversation.js b/api/models/Conversation.js index 6a2fbfb1d1..9d56ee48c1 100644 --- a/api/models/Conversation.js +++ b/api/models/Conversation.js @@ -54,8 +54,6 @@ module.exports = { const cache = {}; const convoMap = {}; const promises = []; - // will handle a syncing solution soon - const deletedConvoIds = []; convoIds.forEach((convo) => promises.push( @@ -66,23 +64,17 @@ module.exports = { ), ); - const results = (await Promise.all(promises)).filter((convo, i) => { - if (!convo) { - deletedConvoIds.push(convoIds[i].conversationId); - return false; - } else { - const page = Math.floor(i / pageSize) + 1; - if (!cache[page]) { - cache[page] = []; - } - cache[page].push(convo); - convoMap[convo.conversationId] = convo; - return true; + const results = (await Promise.all(promises)).filter(Boolean); + + results.forEach((convo, i) => { + const page = Math.floor(i / pageSize) + 1; + if (!cache[page]) { + cache[page] = []; } + cache[page].push(convo); + convoMap[convo.conversationId] = convo; }); - // const startIndex = (pageNumber - 1) * pageSize; - // const convos = results.slice(startIndex, startIndex + pageSize); const totalPages = Math.ceil(results.length / pageSize); cache.pages = totalPages; cache.pageSize = pageSize; @@ -92,8 +84,6 @@ module.exports = { pages: totalPages || 1, pageNumber, pageSize, - // will handle a syncing solution soon - filter: new Set(deletedConvoIds), convoMap, }; } catch (error) { diff --git a/api/models/plugins/mongoMeili.js b/api/models/plugins/mongoMeili.js index cbb7d4faa3..4d97ed5d03 100644 --- a/api/models/plugins/mongoMeili.js +++ b/api/models/plugins/mongoMeili.js @@ -153,7 +153,7 @@ const createMeiliMongooseModel = function ({ index, attributesToIndex }) { }, { _id: 1 }, ), - ); + ).lean(); // Add additional data from mongodb into Meili search hits const populatedHits = data.hits.map(function (hit) { @@ -162,7 +162,7 @@ const createMeiliMongooseModel = function ({ index, attributesToIndex }) { const originalHit = _.find(hitsFromMongoose, query); return { - ...(originalHit ? originalHit.toJSON() : {}), + ...(originalHit ?? {}), ...hit, }; });