Skip to content

Commit

Permalink
Merge pull request #197 from thanhson1085/master
Browse files Browse the repository at this point in the history
 fix parallel save #196
  • Loading branch information
thanhson1085 committed Sep 9, 2018
2 parents 0cfd00f + 387a854 commit a4d187d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const db = require('./models/mongodb')
const config = require('config')
const q = require('./queues')

process.setMaxListeners(1000)
process.setMaxListeners(200)

async function watchBlockSigner () {
let bs = await BlockSigner.deployed()
Expand Down Expand Up @@ -77,15 +77,13 @@ async function watchValidator () {
return false
}
console.info('TomoValidator - New event %s from block %s', res.event, res.blockNumber)
if (cs) {
cs.blockNumber = res.blockNumber
} else {
cs = new db.CrawlState({
smartContractAddress: v.address,
blockNumber: res.blockNumber
})
}
let event = res.event
await db.CrawlState.updateOne({
smartContractAddress: v.address
}, { $set:{
smartContractAddress: v.address,
blockNumber: res.blockNumber
} }, { upsert: true })
if (event === 'Withdraw') {
let owner = res.args._owner
let blockNumber = res.args._blockNumber
Expand All @@ -98,7 +96,6 @@ async function watchValidator () {
capacity: capacity
})
wd.save()
cs.save()
return true
}
let candidate = res.args._candidate
Expand All @@ -115,7 +112,6 @@ async function watchValidator () {
capacity: capacity
})
tx.save()
cs.save()
if (event === 'Vote' || event === 'Unvote') {
updateVoterCap(candidate, voter)
}
Expand Down

0 comments on commit a4d187d

Please sign in to comment.