If block exists in memory cache, return it directly for /block API

This commit is contained in:
nymkappa 2022-04-20 13:40:10 +09:00
parent 067d160f33
commit ff74e6ea8c
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04

View File

@ -392,6 +392,12 @@ class Blocks {
* 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> {
// Check the memory cache
const blockByHash = this.getBlocks().find((b) => b.id === hash);
if (blockByHash) {
return blockByHash;
}
// Block has already been indexed
if (Common.indexingEnabled()) {
const dbBlock = await blocksRepository.$getBlockByHash(hash);