wdb-migrations: add block time cache.
This commit is contained in:
parent
9d211814c1
commit
a03ddce604
2 changed files with 15 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ const Logger = require('blgr');
|
|||
const bdb = require('bdb');
|
||||
const bio = require('bufio');
|
||||
const {BufferSet} = require('buffer-map');
|
||||
const LRU = require('blru');
|
||||
const HDPublicKey = require('../hd/public');
|
||||
const binary = require('../utils/binary');
|
||||
const {encoding} = bio;
|
||||
|
|
@ -808,6 +809,8 @@ class MigrateTXCountTimeIndex extends AbstractMigration {
|
|||
this.unconfirmedBatchSize = 1000;
|
||||
|
||||
this.UNCONFIRMED_HEIGHT = 0xffffffff;
|
||||
|
||||
this.blockTimeCache = new LRU(50);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1101,6 +1104,10 @@ class MigrateTXCountTimeIndex extends AbstractMigration {
|
|||
return null;
|
||||
|
||||
const rawPath = await this.ldb.get(this.layout.wdb.P.encode(wid, hash));
|
||||
|
||||
if (!rawPath)
|
||||
return null;
|
||||
|
||||
const account = encoding.readU32(rawPath, 0);
|
||||
return account;
|
||||
}
|
||||
|
|
@ -1128,6 +1135,11 @@ class MigrateTXCountTimeIndex extends AbstractMigration {
|
|||
|
||||
async getMedianTime(height) {
|
||||
const getBlockTime = async (height) => {
|
||||
const cache = this.blockTimeCache.get(height);
|
||||
|
||||
if (cache != null)
|
||||
return cache;
|
||||
|
||||
const data = await this.ldb.get(this.layout.wdb.h.encode(height));
|
||||
|
||||
if (!data)
|
||||
|
|
@ -1135,6 +1147,8 @@ class MigrateTXCountTimeIndex extends AbstractMigration {
|
|||
|
||||
const time = encoding.readU64(data, 32);
|
||||
|
||||
this.blockTimeCache.set(height, time);
|
||||
|
||||
return time;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ exports.dumpChainDB = async (chaindb, prefixes) => {
|
|||
* @param {Boolean} options.throw - throw on error.
|
||||
* @param {Boolean} options.bail - bail on first error.
|
||||
* @param {Boolean} options.logErrors - log errors.
|
||||
* @returns {Promise<[]String>} - errors.
|
||||
* @returns {Promise<String[]>} - errors.
|
||||
*/
|
||||
|
||||
exports.checkEntries = async (ldb, options) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue