feat: add addToSet update operation to saveConvo to efficiently update modelHistory whenever a new model/endpoint combo is used

This commit is contained in:
Dustin Healy 2025-09-13 12:59:33 -07:00
parent cb8e76e27e
commit 465c81adee
2 changed files with 11 additions and 1 deletions

View file

@ -112,8 +112,17 @@ module.exports = {
update.expiredAt = null;
}
/** @type {{ $set: Partial<TConversation>; $unset?: Record<keyof TConversation, number> }} */
/** @type {{ $set: Partial<TConversation>; $addToSet?: Record<string, any>; $unset?: Record<keyof TConversation, number> }} */
const updateOperation = { $set: update };
if (convo.model && convo.endpoint) {
updateOperation.$addToSet = {
modelHistory: {
model: convo.model,
endpoint: convo.endpoint,
},
};
}
if (metadata && metadata.unsetFields && Object.keys(metadata.unsetFields).length > 0) {
updateOperation.$unset = metadata.unsetFields;
}

View file

@ -51,6 +51,7 @@ export const excludedKeys = new Set([
'_id',
'tools',
'model',
'modelHistory',
'files',
'spec',
'disableParams',