chore: make transaction logs trace

This commit is contained in:
Adhiraj Singh
2022-06-05 13:59:51 +05:30
parent 06fdf5fdac
commit 6f48bbb736

View File

@@ -75,15 +75,17 @@ export const addTransactionCapability = (state: SignalKeyStore, logger: Logger,
return prefetch(type, ids) return prefetch(type, ids)
}, },
transaction: async(work) => { transaction: async(work) => {
// if we're already in a transaction,
// just execute what needs to be executed -- no commit required
if(inTransaction) { if(inTransaction) {
await work() await work()
} else { } else {
logger.debug('entering transaction') logger.trace('entering transaction')
inTransaction = true inTransaction = true
try { try {
await work() await work()
if(Object.keys(mutations).length) { if(Object.keys(mutations).length) {
logger.debug('committing transaction') logger.trace('committing transaction')
// retry mechanism to ensure we've some recovery // retry mechanism to ensure we've some recovery
// in case a transaction fails in the first attempt // in case a transaction fails in the first attempt
let tries = maxCommitRetries let tries = maxCommitRetries
@@ -91,6 +93,7 @@ export const addTransactionCapability = (state: SignalKeyStore, logger: Logger,
tries -= 1 tries -= 1
try { try {
await state.set(mutations) await state.set(mutations)
logger.trace('committed transaction')
break break
} catch(error) { } catch(error) {
logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`) logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`)
@@ -98,7 +101,7 @@ export const addTransactionCapability = (state: SignalKeyStore, logger: Logger,
} }
} }
} else { } else {
logger.debug('no mutations in transaction') logger.trace('no mutations in transaction')
} }
} finally { } finally {
inTransaction = false inTransaction = false