-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Massive performance improvement... #363
base: master
Are you sure you want to change the base?
Changes from all commits
917b9c6
8f9945b
0a10086
45c5f53
ca20343
5a28894
263140e
4f7f61b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,37 +23,40 @@ mongoose.connect(dbString, function(err) { | |
console.log('Aborting'); | ||
exit(); | ||
} else { | ||
var peers = Array(); | ||
var cnt = 0; | ||
request({uri: 'http://127.0.0.1:' + settings.port + '/api/getpeerinfo', json: true}, function (error, response, body) { | ||
lib.syncLoop(body.length, function (loop) { | ||
var i = loop.iteration(); | ||
var address = body[i].addr.split(':')[0]; | ||
var port = body[i].addr.split(':')[1]; | ||
db.find_peer(address, function(peer) { | ||
if (peer) { | ||
if (isNaN(peer['port']) || peer['port'].length < 2 || peer['country'].length < 1) { | ||
db.drop_peers(function() { | ||
console.log('Saved peers missing ports or country, dropping peers. Re-reun this script afterwards.'); | ||
exit(); | ||
}); | ||
} | ||
// peer already exists | ||
loop.next(); | ||
} else { | ||
request({uri: 'https://freegeoip.app/json/' + address, json: true}, function (error, response, geo) { | ||
db.create_peer({ | ||
address: address, | ||
port: port, | ||
protocol: body[i].version, | ||
version: body[i].subver.replace('/', '').replace('/', ''), | ||
country: geo.country_name | ||
}, function(){ | ||
loop.next(); | ||
}); | ||
}); | ||
request({uri: 'https://freegeoip.app/json/' + address, json: true}, function (error, response, geo) { | ||
if (address.startsWith('10.') || address.startsWith('192.168') || address.startsWith('172.16')) { | ||
geo.country_name = '[private address]'; | ||
} | ||
peers[cnt++] = { | ||
address: address, | ||
port: port, | ||
protocol: body[i].version, | ||
version: body[i].subver.replace('/', '').replace('/', ''), | ||
country: geo.country_name | ||
}; | ||
loop.next(); | ||
}); | ||
}, function() { | ||
exit(); | ||
|
||
// insert all at once after creation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks good, much better way of doing it |
||
db.drop_peers(function() { | ||
console.log('Dropped, rebuilding...'); | ||
lib.syncLoop(cnt, function (loop) { | ||
var i = loop.iteration(); | ||
db.create_peer(peers[i], function() { | ||
loop.next(); | ||
}); | ||
}, function() { | ||
exit(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ html | |
function update_stats(){ | ||
$.ajax({url: '/ext/summary', success: function(json){ | ||
$("#supply").text(parseInt(parseFloat(json.data[0].supply).toFixed(0)).toLocaleString('en')); | ||
$("#difficulty").text(parseFloat(json.data[0].difficulty).toFixed(2)); | ||
$("#difficulty").text(json.data[0].difficulty); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we changing this? If you want this formatted differently then we should add config options for it in a separate PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in b7180dc |
||
$("#difficultyHybrid").text(json.data[0].difficultyHybrid); | ||
$("#hashrate").text(parseFloat(json.data[0].hashrate).toLocaleString('en')); | ||
$("#lastPrice").text(parseFloat(json.data[0].lastPrice).toFixed(8) + ' #{settings.markets.exchange}'.toUpperCase()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@typhoonsimon As per the function's name "get_last_txs_ajax" - this function does NOT show latest blocks - it shows Latest Transactions, we cannot use the blockcount call here.
This does look very efficient though and would work almost as is for an additional function for latest blocks, which we could then set in the config for the user to display latest TX or latest BLOCKS on the front page.
In terms of making this code work for latest TXs what's the performance difference of Tx.countDocuments vs Tx.count here?
tx_count might be a stat we should keep updated via block indexing?