Skip to content

Commit

Permalink
optimize balances
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneight committed Jul 8, 2020
1 parent a0cbbaa commit fd2a743
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/blockexplorerapi/readAllBlocksToDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ async function getTransactionLog(transaction) {
}

let balancesToGet = {};
let addressQueue = {};

async function getBalances(sql, conn, addrs, index) {
if ( !sql ) {
Expand Down Expand Up @@ -659,12 +660,15 @@ async function getBalances(sql, conn, addrs, index) {
!address ||
address === web3.fsn.consts.FSNCallAddress ||
address === web3.fsn.consts.TicketLogAddress ||
address.length === 0
address.length === 0 ||
addressQueue[address]
) {
return getBalances(sql, conn, addrs, index + 1, resolve, reject);
console.log("ALREADY GETTING BALANCE " + address);
return getBalances(sql, conn, addrs, index + 1);
}

let all;
addressQueue[address] = true;

if (balancesReturned[address] && balancesReturned[address] > lastBlock) {
// we have this balance already
Expand Down Expand Up @@ -713,9 +717,9 @@ async function getBalances(sql, conn, addrs, index) {
`VALUES( "${address}", NOW(), NOW(), ${count}, ${assetsHeld}, '${fsnBalance}', '${notation}', '${all}' )\n` +
`ON DUPLICATE KEY UPDATE recEdited = NOW(), assetsHeld = ${assetsHeld}, fsnBalance = '${fsnBalance}', numberOfTransactions = ${count}, san = '${notation}', balanceInfo = '${all}' ;\n`;


balancesReturned[address] = glb_highestBlockOnChain;

delete addressQueue[address];

getBalances(sql,conn, addrs, index + 1);
} catch (err) {
if ( conn && !conn.__released ) {
Expand Down

0 comments on commit fd2a743

Please sign in to comment.