perf(addTransactionCapability): streamline transaction handling and improve concurrency control (#1887)

This commit is contained in:
João Lucas de Oliveira Lopes
2025-10-08 16:14:58 -03:00
committed by GitHub
parent f56293365f
commit 051b5fc220
+2 -4
View File
@@ -116,7 +116,6 @@ export const addTransactionCapability = (
logger: ILogger,
{ maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions
): SignalKeyStoreWithTransaction => {
// AsyncLocalStorage for transaction context
const txStorage = new AsyncLocalStorage<TransactionContext>()
// Queues for concurrency control
@@ -189,9 +188,8 @@ export const addTransactionCapability = (
const ctx = txStorage.getStore()
if (!ctx) {
// No transaction - direct read with mutex protection (not queue)
// Use mutex instead of queue to provide mutual exclusion for reads and writes, reducing queuing overhead and improving event loop responsiveness (does not allow concurrent reads)
return getTxMutex(type).runExclusive(() => state.get(type, ids))
// No transaction - direct read without exclusive lock for concurrency
return state.get(type, ids)
}
// In transaction - check cache first