mirror of
https://github.com/jwinterm/nodejs-pool.git
synced 2026-10-22 06:08:34 +02:00
New cache function for bulk-inserts in single txn to avoid excessive disk writes and blocking by worker.
Adding new getBlockByID function for future tool functionality.
This commit is contained in:
@@ -218,6 +218,21 @@ function Database(){
|
||||
return highestBlock;
|
||||
};
|
||||
|
||||
this.getBlockByID = function(blockID){
|
||||
this.refreshEnv();
|
||||
debug("Getting the data for blockID: " + blockID);
|
||||
let txn = this.env.beginTxn({readOnly: true});
|
||||
let data = txn.getBinary(blockID);
|
||||
if (data === null){
|
||||
debug("Unable to get block at height: "+ blockID);
|
||||
return false;
|
||||
}
|
||||
let blockData = global.protos.Block.decode(data);
|
||||
txn.commit();
|
||||
debug("Done getting the last block for: "+ blockData.poolType + " height of: "+ blockID);
|
||||
return blockData;
|
||||
};
|
||||
|
||||
this.calculateShares = function(blockData, blockHeight){
|
||||
debug("Calculating shares for "+ blockData.hash);
|
||||
this.refreshEnv();
|
||||
@@ -376,6 +391,16 @@ function Database(){
|
||||
txn.commit();
|
||||
};
|
||||
|
||||
this.bulkSetCache = function(cacheUpdates){
|
||||
let txn = this.env.beginTxn();
|
||||
for (let key in cacheUpdates){
|
||||
if (cacheUpdates.hasOwnProperty(key)){
|
||||
txn.putString(this.cacheDB, key, JSON.stringify(cacheUpdates[key]));
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
};
|
||||
|
||||
this.cleanShareDB = function() {
|
||||
/*
|
||||
This function takes the difficulty of the current block, and the last PPS block. If it's 0, save everything,
|
||||
|
||||
Reference in New Issue
Block a user