fix up sweeping

This commit is contained in:
Josh Harvey 2016-06-03 03:14:22 +03:00
parent 751067bace
commit 19ebf9d2a2
4 changed files with 37 additions and 22 deletions

View file

@ -332,10 +332,7 @@ exports.updateTxStatus = function updateTxStatus (tx, status) {
const values2 = [newStatus, tx.sessionId]
return t.none(sql2, values2)
.then(() => {
const sql3 = 'insert into cash_out_actions (session_id, action) values ($1, $2)'
return t.none(sql3, [tx.sessionId, newStatus])
})
.then(() => ({status: newStatus}))
})
}
@ -344,6 +341,18 @@ exports.updateTxStatus = function updateTxStatus (tx, status) {
// Note: don't worry about retrying failed transaction here
// It will be tried again on the next status check
return db.tx(transaction)
.then(r => {
if (!r) return
const sql3 = 'insert into cash_out_actions (session_id, action) values ($1, $2)'
return db.none(sql3, [tx.sessionId, r.status])
.then(() => {
if (r.status === 'confirmed') {
const sql4 = `update cash_out_hds set confirmed=true where session_id=$1`
return db.none(sql4, [tx.sessionId])
}
})
})
}
exports.updateRedeem = function updateRedeem (session) {
@ -449,23 +458,12 @@ exports.fetchLiveHD = function fetchLiveHD () {
}
exports.fetchOldHD = function fetchLiveHD () {
db.one(`select reltuples as approximate_row_count from pg_class where relname = 'cash_out_txs'`)
.then(row => {
const rowCount = row.approximate_row_count
const sql = `select * from cash_out_hds
where confirmed
order by last_checked
limit 10`
const factor = rowCount < 1000
? 10
: rowCount < 10000 ? 1 : 0.1
const sql = `select * from cash_out_txs tablesample system $1,
cash_out_hds
where cash_out_txs.session_id=cash_out_hds.session_id
and status=$2`
const values = [factor, 'confirmed']
return db.manyOrNone(sql, values)
})
return db.manyOrNone(sql)
}
exports.markSwept = function markSwept (sessionId) {