mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
fix(meilisearch): results will now properly paginate
This commit is contained in:
parent
428fd5bed8
commit
a2b6e9a6a8
2 changed files with 10 additions and 20 deletions
|
|
@ -54,8 +54,6 @@ module.exports = {
|
||||||
const cache = {};
|
const cache = {};
|
||||||
const convoMap = {};
|
const convoMap = {};
|
||||||
const promises = [];
|
const promises = [];
|
||||||
// will handle a syncing solution soon
|
|
||||||
const deletedConvoIds = [];
|
|
||||||
|
|
||||||
convoIds.forEach((convo) =>
|
convoIds.forEach((convo) =>
|
||||||
promises.push(
|
promises.push(
|
||||||
|
|
@ -66,23 +64,17 @@ module.exports = {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
const results = (await Promise.all(promises)).filter((convo, i) => {
|
const results = (await Promise.all(promises)).filter(Boolean);
|
||||||
if (!convo) {
|
|
||||||
deletedConvoIds.push(convoIds[i].conversationId);
|
results.forEach((convo, i) => {
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
const page = Math.floor(i / pageSize) + 1;
|
const page = Math.floor(i / pageSize) + 1;
|
||||||
if (!cache[page]) {
|
if (!cache[page]) {
|
||||||
cache[page] = [];
|
cache[page] = [];
|
||||||
}
|
}
|
||||||
cache[page].push(convo);
|
cache[page].push(convo);
|
||||||
convoMap[convo.conversationId] = convo;
|
convoMap[convo.conversationId] = convo;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// const startIndex = (pageNumber - 1) * pageSize;
|
|
||||||
// const convos = results.slice(startIndex, startIndex + pageSize);
|
|
||||||
const totalPages = Math.ceil(results.length / pageSize);
|
const totalPages = Math.ceil(results.length / pageSize);
|
||||||
cache.pages = totalPages;
|
cache.pages = totalPages;
|
||||||
cache.pageSize = pageSize;
|
cache.pageSize = pageSize;
|
||||||
|
|
@ -92,8 +84,6 @@ module.exports = {
|
||||||
pages: totalPages || 1,
|
pages: totalPages || 1,
|
||||||
pageNumber,
|
pageNumber,
|
||||||
pageSize,
|
pageSize,
|
||||||
// will handle a syncing solution soon
|
|
||||||
filter: new Set(deletedConvoIds),
|
|
||||||
convoMap,
|
convoMap,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ const createMeiliMongooseModel = function ({ index, attributesToIndex }) {
|
||||||
},
|
},
|
||||||
{ _id: 1 },
|
{ _id: 1 },
|
||||||
),
|
),
|
||||||
);
|
).lean();
|
||||||
|
|
||||||
// Add additional data from mongodb into Meili search hits
|
// Add additional data from mongodb into Meili search hits
|
||||||
const populatedHits = data.hits.map(function (hit) {
|
const populatedHits = data.hits.map(function (hit) {
|
||||||
|
|
@ -162,7 +162,7 @@ const createMeiliMongooseModel = function ({ index, attributesToIndex }) {
|
||||||
const originalHit = _.find(hitsFromMongoose, query);
|
const originalHit = _.find(hitsFromMongoose, query);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...(originalHit ? originalHit.toJSON() : {}),
|
...(originalHit ?? {}),
|
||||||
...hit,
|
...hit,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue