mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-07-11 08:43:48 +00:00
refactor(agents): streamline bulk write logic in recordCollectedUsage function
Removed redundant bulk write operations and consolidated document handling in the recordCollectedUsage function. The logic now combines all documents into a single bulk write operation, improving efficiency and reducing error handling complexity. Updated logging to provide consistent error messages for bulk write failures.
This commit is contained in:
parent
4ca86fae3d
commit
908a08fd99
1 changed files with 4 additions and 11 deletions
|
|
@ -182,14 +182,6 @@ export async function recordCollectedUsage(
|
|||
});
|
||||
}
|
||||
|
||||
if (useBulk && allDocs.length > 0) {
|
||||
try {
|
||||
await bulkWriteTransactions({ user, docs: allDocs }, bulkWriteOps);
|
||||
} catch (err) {
|
||||
logger.error('[packages/api #recordCollectedUsage] Error in bulk write', err);
|
||||
}
|
||||
}
|
||||
|
||||
const summarizationDocs: PreparedEntry[] = [];
|
||||
|
||||
for (const usage of summarizationUsages) {
|
||||
|
|
@ -273,11 +265,12 @@ export async function recordCollectedUsage(
|
|||
});
|
||||
}
|
||||
|
||||
if (useBulk && summarizationDocs.length > 0) {
|
||||
const combinedDocs = [...allDocs, ...summarizationDocs];
|
||||
if (useBulk && combinedDocs.length > 0) {
|
||||
try {
|
||||
await bulkWriteTransactions({ user, docs: summarizationDocs }, bulkWriteOps);
|
||||
await bulkWriteTransactions({ user, docs: combinedDocs }, bulkWriteOps);
|
||||
} catch (err) {
|
||||
logger.error('[packages/api #recordCollectedUsage] Error in summarization bulk write', err);
|
||||
logger.error('[packages/api #recordCollectedUsage] Error in bulk write', err);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue