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

This commit is contained in:
nymkappa committed 2022-05-12 08:13:41 +02:00
1 parent 771ab36694
commit ec37cc5952
1 file changed
+6
+6
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);