From ff74e6ea8caca1a8f35bc25c6d01982cacf0ab0e Mon Sep 17 00:00:00 2001 From: nymkappa Date: Wed, 20 Apr 2022 13:40:10 +0900 Subject: [PATCH] If block exists in memory cache, return it directly for /block API --- backend/src/api/blocks.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index a723f8069..9d2e91c78 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -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 { + // 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);