Added tx cache.
This commit is contained in:
parent
18bb501547
commit
22678e3838
16
errors.txt
Normal file
16
errors.txt
Normal file
@ -0,0 +1,16 @@
|
||||
17-10-16T23:06:28.131Z] error: Error: Block hash or address expected
|
||||
Oct 16 23:06:28 rs-iad-insight-04 bitcored[23072]: at TxController.list (/home/bitcore/.npm-packages/lib/node_modules/bitcore/node_modules/insight-api/lib/transactions.js:321:37)
|
||||
Oct 16 23:06:28 rs-iad-insight-04 bitcored[23072]: at Layer.handle [as handle_request] (/home/bitcore/.npm-packages/lib/node_modules/bitcore/node_modules/express/lib/router/layer.js:95:5)
|
||||
Oct 16 23:06:28 rs-iad-insight-04 bitcored[23072]: at next (/home/bitcore/.npm-packages/lib/node_modules/bitcore/node_modules/express/lib/router/route.js:137:13)
|
||||
Oct 16 23:06:28 rs-iad-insight-04 bitcored[23072]: at /home/bitcore/.npm-packages/lib/node_modules/bitcore/node_modules/insight-api/lib/index.js:73:5
|
||||
Oct 16 23:06:28 rs-iad-insight-04 bitcored[23072]: at Layer.handle [as handle_request] (/home/bitcore/.npm-packages/lib/node_modules/bitcore/node_modules/express/lib/router/layer.js:95:5)
|
||||
Oct 16 23:06:28 rs-iad-insight-04 bitcored[23072]: at next (/home/bitcore/.npm-packages/lib/node_modules/bitcore/node_modules/express/lib/router/route.js:137:13)
|
||||
Oct 16 23:06:28 rs-iad-insight-04 bitcored[23072]: at Route.dispatch (/home/bitcore/.npm-packages/lib/node_modules/bitcore/node_modules/express/lib/router/route.js:112:3)
|
||||
Oct 16 23:06:28 rs-iad-insight-04 bitcored[23072]: at Layer.handle [as handle_request] (/home/bitcore/.npm-packages/lib/node_modules/bitcore/node_modules/express/lib/router/layer.js:95:5)
|
||||
Oct 16 23:06:28 rs-iad-insight-04 bitcored[23072]: at /home/bitcore/.npm-packages/lib/node_modules/bitcore/node_modules/express/lib/router/index.js:281:22
|
||||
Oct 16 23:06:28 rs-iad-insight-04 bitcored[23072]: at
|
||||
|
||||
|
||||
|
||||
17
|
||||
|
||||
@ -6,6 +6,7 @@ var Encoding = require('./encoding');
|
||||
var _ = require('lodash');
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var LRU = require('lru-cache');
|
||||
|
||||
function TransactionService(options) {
|
||||
BaseService.call(this, options);
|
||||
@ -24,6 +25,9 @@ function TransactionService(options) {
|
||||
if (this._network === 'regtest') {
|
||||
this._network = 'testnet';
|
||||
}
|
||||
|
||||
// caches
|
||||
this._cacheTx = LRU(1000);
|
||||
}
|
||||
|
||||
inherits(TransactionService, BaseService);
|
||||
@ -113,12 +117,25 @@ TransactionService.prototype.getTransaction = function(txid, options, callback)
|
||||
callback = options;
|
||||
}
|
||||
|
||||
var cacheTx = self._cacheTx.get(txid);
|
||||
if (cacheTx) {
|
||||
return callback(null, cacheTx);
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
self._getTransaction.bind(self, txid, options),
|
||||
self._getSupplementaryTransactionInfo.bind(self),
|
||||
self._getMempoolTransaction.bind(self),
|
||||
self.setTxMetaInfo.bind(self)
|
||||
], callback);
|
||||
], function(err, tx) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (tx) {
|
||||
self._cacheTx.set(txid, tx);
|
||||
}
|
||||
callback(err, tx);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user