refactor: query optimization
This commit is contained in:
parent
3846d7f9d7
commit
da6076b359
1 changed files with 20 additions and 6 deletions
|
|
@ -511,17 +511,31 @@ function plugins (settings, deviceId) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function recordTradeAndTx (tradeId, internalTxIdList, dbTx) {
|
async function recordTradeAndTx (tradeId, internalTxIdList, dbTx) {
|
||||||
dbTx.batch(_.map(internalTxId => {
|
const columnSetCashin = new pgp.helpers.ColumnSet(['cash_in_tx_id', 'trade_id'], { table: 'cashin_tx_trades' })
|
||||||
|
const columnSetCashout = new pgp.helpers.ColumnSet(['cash_out_tx_id', 'trade_id'], { table: 'cashout_tx_trades' })
|
||||||
|
let cashinTxs = []
|
||||||
|
let cashoutTxs = []
|
||||||
|
let queries = []
|
||||||
|
_.map(internalTxId => {
|
||||||
let entry = { trade_id: tradeId }
|
let entry = { trade_id: tradeId }
|
||||||
if (internalTxId.direction === 'cashIn') {
|
if (internalTxId.direction === 'cashIn') {
|
||||||
entry.cash_in_tx_id = internalTxId.txId
|
entry.cash_in_tx_id = internalTxId.txId
|
||||||
return dbTx.none(pgp.helpers.insert(entry, null, 'cashin_tx_trades'))
|
cashinTxs.push(entry)
|
||||||
|
} else {
|
||||||
|
entry.cash_out_tx_id = internalTxId.txId
|
||||||
|
cashoutTxs.push(entry)
|
||||||
}
|
}
|
||||||
entry.cash_out_tx_id = internalTxId.txId
|
|
||||||
return dbTx.none(pgp.helpers.insert(entry, null, 'cashout_tx_trades'))
|
|
||||||
}, internalTxIdList)
|
}, internalTxIdList)
|
||||||
)
|
if (!_.isEmpty(cashinTxs)) {
|
||||||
|
const query = pgp.helpers.insert(cashinTxs, columnSetCashin)
|
||||||
|
queries.push(dbTx.none(query))
|
||||||
|
}
|
||||||
|
if (!_.isEmpty(cashoutTxs)) {
|
||||||
|
const query = pgp.helpers.insert(cashoutTxs, columnSetCashout)
|
||||||
|
queries.push(dbTx.none(query))
|
||||||
|
}
|
||||||
|
return Promise.all(queries)
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertBigNumFields (obj) {
|
function convertBigNumFields (obj) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue