mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-03 09:08:52 +01:00
🔀 fix: Remove use of Mongo Transactions (#2525)
* fix: remove use of transactions * fix: remove use of transactions * refactor(actions): perform OpenAI API operation first, before attempting database updates
This commit is contained in:
parent
667f5f91fe
commit
bde6bb0152
3 changed files with 14 additions and 45 deletions
|
|
@ -5,7 +5,6 @@ const handleText = require('./handleText');
|
|||
const cryptoUtils = require('./crypto');
|
||||
const citations = require('./citations');
|
||||
const sendEmail = require('./sendEmail');
|
||||
const mongoose = require('./mongoose');
|
||||
const queue = require('./queue');
|
||||
const files = require('./files');
|
||||
const math = require('./math');
|
||||
|
|
@ -15,7 +14,6 @@ module.exports = {
|
|||
...cryptoUtils,
|
||||
...handleText,
|
||||
...citations,
|
||||
...mongoose,
|
||||
countTokens,
|
||||
removePorts,
|
||||
sendEmail,
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
const mongoose = require('mongoose');
|
||||
/**
|
||||
* Executes a database operation within a session.
|
||||
* @param {() => Promise<any>} method - The method to execute. This method must accept a session as its first argument.
|
||||
* @param {...any} args - Additional arguments to pass to the method.
|
||||
* @returns {Promise<any>} - The result of the executed method.
|
||||
*/
|
||||
async function withSession(method, ...args) {
|
||||
const session = await mongoose.startSession();
|
||||
session.startTransaction();
|
||||
try {
|
||||
const result = await method(...args, session);
|
||||
await session.commitTransaction();
|
||||
return result;
|
||||
} catch (error) {
|
||||
if (session.inTransaction()) {
|
||||
await session.abortTransaction();
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
await session.endSession();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { withSession };
|
||||
Loading…
Add table
Add a link
Reference in a new issue