Commit 1f465db7 authored by Pavel Ševčík's avatar Pavel Ševčík Committed by Pavel Ševčík
Browse files

Serialize DB inserts

parent e4621595
......@@ -123,7 +123,7 @@ class RemoteImporter {
await db.ensureHDAccountId(xpub, type)
const addrChunks = util.splitList(addresses, 1000)
await util.parallelCall(addrChunks, chunk => {
await util.seriesCall(addrChunks, chunk => {
return db.addAddressesToHDAccount(xpub, chunk)
})
......@@ -294,20 +294,20 @@ class RemoteImporter {
*/
async _importTransactions(addresses, txs) {
const addrChunks = util.splitList(addresses, 1000)
const addrIdMaps = await util.parallelCall(addrChunks, chunk => {
const addrIdMaps = await util.seriesCall(addrChunks, chunk => {
return db.getAddressesIds(chunk)
})
const addrIdMap = Object.assign({}, ...addrIdMaps)
// Process the transactions by batches of 200 transactions
const txsChunks = util.splitList(txs, 200)
await util.parallelCall(txsChunks, chunk => {
await util.seriesCall(txsChunks, chunk => {
return this._addTransactions(chunk)
})
await util.parallelCall(txsChunks, chunk => {
await util.seriesCall(txsChunks, chunk => {
return this._addOutputs(chunk, addrIdMap)
})
await util.parallelCall(txsChunks, chunk => {
await util.seriesCall(txsChunks, chunk => {
return this._addInputs(chunk)
})
}
......@@ -340,7 +340,7 @@ class RemoteImporter {
/**
* Add a collection of transaction outputs to the database.
* @param {object[]} txs - array of transaction objects
* @params {object} addrIdMap - map address => addrId
* @param {object} addrIdMap - map address => addrId
* @returns {Promise}
*/
async _addOutputs(txs, addrIdMap) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment