d7c18a48f5
-Added locks to all sync processes (blocks, markets, peers, masternodes) as well as "create backup", "restore backup" and "delete database" functions. This helps prevent problems with syncing data while a backup is in progress for example -The code to initialize certain database collections on startup was moved into database.js and is now called from restore_backup.js and delete_database.js. This effectively allows the database to be deleted or restored to a completely different backup while the explorer is still running -Lock functions (create_lock, remove_lock, is_locked) were moved into explorer.js for better reusability and rewriten to be synchronous -is_locked function now accepts an array of lock files to be able to check for multiple locks in a single call -remove_sync_message() function was moved into database.js so that restore_backup.js and delete_database.js can also check for and remove the sync msg if it exists -Useful Scripts section updated in the README to make it clear that the explorer no longer needs to be stopped for these scripts to be run -Most if not all log messages now start with a capitlal letter
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
var mongoose = require('mongoose'),
|
|
db = require('../lib/database'),
|
|
Tx = require('../models/tx'),
|
|
Address = require('../models/address'),
|
|
settings = require('../lib/settings');
|
|
|
|
var COUNT = 5000; // number of blocks to index
|
|
|
|
function exit(exitCode) {
|
|
mongoose.disconnect();
|
|
process.exit(exitCode);
|
|
}
|
|
|
|
var dbString = 'mongodb://' + settings.dbsettings.user;
|
|
dbString = dbString + ':' + settings.dbsettings.password;
|
|
dbString = dbString + '@' + settings.dbsettings.address;
|
|
dbString = dbString + ':' + settings.dbsettings.port;
|
|
dbString = dbString + "/IQUIDUS-BENCHMARK";
|
|
|
|
mongoose.connect(dbString, function(err) {
|
|
if (err) {
|
|
console.log('Error: Unable to connect to database: %s', dbString);
|
|
exit(999);
|
|
}
|
|
|
|
Tx.deleteMany({}, function(err) {
|
|
Address.deleteMany({}, function(err2) {
|
|
var s_timer = new Date().getTime();
|
|
|
|
db.update_tx_db(settings.coin.name, 1, COUNT, 0, settings.sync.update_timeout, false, function() {
|
|
var e_timer = new Date().getTime();
|
|
|
|
Tx.countDocuments({}, function(txerr, txcount) {
|
|
Address.countDocuments({}, function(aerr, acount) {
|
|
var stats = {
|
|
tx_count: txcount,
|
|
address_count: acount,
|
|
seconds: (e_timer - s_timer)/1000,
|
|
};
|
|
|
|
console.log(stats);
|
|
exit(0);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}); |