If block exists in memory cache, return it directly for /block API
This commit is contained in:
parent
067d160f33
commit
ff74e6ea8c
@ -392,6 +392,12 @@ class Blocks {
|
|||||||
* Index a block by hash if it's missing from the database. Returns the block after indexing
|
* Index a block by hash if it's missing from the database. Returns the block after indexing
|
||||||
*/
|
*/
|
||||||
public async $getBlock(hash: string): Promise<BlockExtended | IEsploraApi.Block> {
|
public async $getBlock(hash: string): Promise<BlockExtended | IEsploraApi.Block> {
|
||||||
|
// Check the memory cache
|
||||||
|
const blockByHash = this.getBlocks().find((b) => b.id === hash);
|
||||||
|
if (blockByHash) {
|
||||||
|
return blockByHash;
|
||||||
|
}
|
||||||
|
|
||||||
// Block has already been indexed
|
// Block has already been indexed
|
||||||
if (Common.indexingEnabled()) {
|
if (Common.indexingEnabled()) {
|
||||||
const dbBlock = await blocksRepository.$getBlockByHash(hash);
|
const dbBlock = await blocksRepository.$getBlockByHash(hash);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user