🗄️ 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:
Syed Osama Ali Shah 2026-07-05 19:02:55 +03:00 committed by GitHub
parent 5789f89a3f
commit 13a01dee9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View 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);
});
});

View file

@ -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);
};