mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-07-10 16:23:44 +00:00
🗄️ fix: Return Cached Transaction-Support Value on Cache Hit (#13999)
getTransactionSupport initialized transactionsSupported to false and only assigned it on a cache miss (transactionSupportCache === null), so on a cache hit it returned false regardless of the cached value. After the first bulkUpdateResourcePermissions call populated the cache with true, every later call reported false and the bulk permission writes silently stopped running inside a MongoDB transaction, losing atomicity. Return the cached boolean on a cache hit; the cache-miss path still probes via supportsTransactions. Adds a regression test.
This commit is contained in:
parent
5789f89a3f
commit
13a01dee9b
2 changed files with 14 additions and 4 deletions
11
packages/data-schemas/src/utils/transactions.spec.ts
Normal file
11
packages/data-schemas/src/utils/transactions.spec.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { getTransactionSupport } from './transactions';
|
||||
|
||||
describe('getTransactionSupport', () => {
|
||||
// The cache-hit path does not touch the database, so a stub mongoose is fine.
|
||||
const mongoose = {} as unknown as typeof import('mongoose');
|
||||
|
||||
it('returns the cached value on a cache hit (does not re-probe)', async () => {
|
||||
await expect(getTransactionSupport(mongoose, true)).resolves.toBe(true);
|
||||
await expect(getTransactionSupport(mongoose, false)).resolves.toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -55,9 +55,8 @@ export const getTransactionSupport = async (
|
|||
mongoose: typeof import('mongoose'),
|
||||
transactionSupportCache: boolean | null,
|
||||
): Promise<boolean> => {
|
||||
let transactionsSupported = false;
|
||||
if (transactionSupportCache === null) {
|
||||
transactionsSupported = await supportsTransactions(mongoose);
|
||||
if (transactionSupportCache !== null) {
|
||||
return transactionSupportCache;
|
||||
}
|
||||
return transactionsSupported;
|
||||
return await supportsTransactions(mongoose);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue