From 45a1e849fd927037f5738124ef0d937593656f07 Mon Sep 17 00:00:00 2001 From: Mugdha Goel <106084778+mgoelswirlds@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:34:51 -0400 Subject: [PATCH] Increase max age for entity list endpoints (#9223) Description: - Increases max age for entity list endpoints in order to improve performance for these endpoints. - Adds a note for extended caching to the openapi.yaml --------- Signed-off-by: mgoelswirlds --- .../__tests__/middleware/responseHandler.test.js | 2 +- .../__tests__/specs/accounts/responseHeaders.json | 3 +++ .../__tests__/specs/contracts/responseHeaders.json | 3 +++ .../specs/contracts/results/responseHeaders.json | 3 +++ .../__tests__/specs/contracts/{id}/responseHeaders.json | 3 +++ .../__tests__/specs/schedules/responseHeaders.json | 3 +++ .../__tests__/specs/schedules/{id}/responseHeaders.json | 3 +++ .../__tests__/specs/tokens/responseHeaders.json | 3 +++ hedera-mirror-rest/api/v1/openapi.yml | 8 ++++---- hedera-mirror-rest/config/application.yml | 7 +++++++ 10 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 hedera-mirror-rest/__tests__/specs/accounts/responseHeaders.json create mode 100644 hedera-mirror-rest/__tests__/specs/contracts/responseHeaders.json create mode 100644 hedera-mirror-rest/__tests__/specs/contracts/results/responseHeaders.json create mode 100644 hedera-mirror-rest/__tests__/specs/contracts/{id}/responseHeaders.json create mode 100644 hedera-mirror-rest/__tests__/specs/schedules/responseHeaders.json create mode 100644 hedera-mirror-rest/__tests__/specs/schedules/{id}/responseHeaders.json create mode 100644 hedera-mirror-rest/__tests__/specs/tokens/responseHeaders.json diff --git a/hedera-mirror-rest/__tests__/middleware/responseHandler.test.js b/hedera-mirror-rest/__tests__/middleware/responseHandler.test.js index 9fe0bdff8b5..4cf0d8aedb0 100644 --- a/hedera-mirror-rest/__tests__/middleware/responseHandler.test.js +++ b/hedera-mirror-rest/__tests__/middleware/responseHandler.test.js @@ -69,7 +69,7 @@ describe('Response middleware', () => { await responseHandler(mockRequest, mockResponse, null); expect(mockResponse.send).toBeCalledWith(JSONStringify(responseData)); expect(mockResponse.set).toHaveBeenNthCalledWith(1, headers.default); - expect(mockResponse.set).toHaveBeenNthCalledWith(2, undefined); + expect(mockResponse.set).toHaveBeenNthCalledWith(2, headers.path[mockRequest.route.path]); expect(mockResponse.set).toHaveBeenNthCalledWith(3, 'Content-Type', 'application/json; charset=utf-8'); expect(mockResponse.status).toBeCalledWith(mockResponse.locals.statusCode); }); diff --git a/hedera-mirror-rest/__tests__/specs/accounts/responseHeaders.json b/hedera-mirror-rest/__tests__/specs/accounts/responseHeaders.json new file mode 100644 index 00000000000..6da8c65129e --- /dev/null +++ b/hedera-mirror-rest/__tests__/specs/accounts/responseHeaders.json @@ -0,0 +1,3 @@ +{ + "cache-control": "public, max-age=10" +} diff --git a/hedera-mirror-rest/__tests__/specs/contracts/responseHeaders.json b/hedera-mirror-rest/__tests__/specs/contracts/responseHeaders.json new file mode 100644 index 00000000000..6da8c65129e --- /dev/null +++ b/hedera-mirror-rest/__tests__/specs/contracts/responseHeaders.json @@ -0,0 +1,3 @@ +{ + "cache-control": "public, max-age=10" +} diff --git a/hedera-mirror-rest/__tests__/specs/contracts/results/responseHeaders.json b/hedera-mirror-rest/__tests__/specs/contracts/results/responseHeaders.json new file mode 100644 index 00000000000..6da8c65129e --- /dev/null +++ b/hedera-mirror-rest/__tests__/specs/contracts/results/responseHeaders.json @@ -0,0 +1,3 @@ +{ + "cache-control": "public, max-age=10" +} diff --git a/hedera-mirror-rest/__tests__/specs/contracts/{id}/responseHeaders.json b/hedera-mirror-rest/__tests__/specs/contracts/{id}/responseHeaders.json new file mode 100644 index 00000000000..72af98b4b93 --- /dev/null +++ b/hedera-mirror-rest/__tests__/specs/contracts/{id}/responseHeaders.json @@ -0,0 +1,3 @@ +{ + "cache-control": "public, max-age=1" +} diff --git a/hedera-mirror-rest/__tests__/specs/schedules/responseHeaders.json b/hedera-mirror-rest/__tests__/specs/schedules/responseHeaders.json new file mode 100644 index 00000000000..6da8c65129e --- /dev/null +++ b/hedera-mirror-rest/__tests__/specs/schedules/responseHeaders.json @@ -0,0 +1,3 @@ +{ + "cache-control": "public, max-age=10" +} diff --git a/hedera-mirror-rest/__tests__/specs/schedules/{id}/responseHeaders.json b/hedera-mirror-rest/__tests__/specs/schedules/{id}/responseHeaders.json new file mode 100644 index 00000000000..72af98b4b93 --- /dev/null +++ b/hedera-mirror-rest/__tests__/specs/schedules/{id}/responseHeaders.json @@ -0,0 +1,3 @@ +{ + "cache-control": "public, max-age=1" +} diff --git a/hedera-mirror-rest/__tests__/specs/tokens/responseHeaders.json b/hedera-mirror-rest/__tests__/specs/tokens/responseHeaders.json new file mode 100644 index 00000000000..6da8c65129e --- /dev/null +++ b/hedera-mirror-rest/__tests__/specs/tokens/responseHeaders.json @@ -0,0 +1,3 @@ +{ + "cache-control": "public, max-age=10" +} diff --git a/hedera-mirror-rest/api/v1/openapi.yml b/hedera-mirror-rest/api/v1/openapi.yml index b77f0ccb0c9..a8ebc5ab064 100644 --- a/hedera-mirror-rest/api/v1/openapi.yml +++ b/hedera-mirror-rest/api/v1/openapi.yml @@ -1318,7 +1318,7 @@ paths: - tokens tags: - name: accounts - description: The accounts object represents the information associated with an account entity and returns a list of account information. + description: The accounts object represents the information associated with an account entity and returns a list of account information.The accounts list endpoint is cached and not updated as frequently as the account lookup by a specific ID endpoint. externalDocs: url: https://docs.hedera.com/guides/docs/mirror-node-api/cryptocurrency-api#accounts - name: balances @@ -1326,9 +1326,9 @@ tags: externalDocs: url: https://docs.hedera.com/guides/docs/mirror-node-api/cryptocurrency-api#balances - name: contracts - description: The contracts objects represents the information associated with contract entities. + description: The contracts objects represents the information associated with contract entities.The contracts list endpoint is cached and not updated as frequently as the contract lookup by a specific ID endpoint. - name: schedules - description: The schedules object represents the information associated with a schedule entity. + description: The schedules object represents the information associated with a schedule entity.The schedules list endpoints is cached and not updated as frequently as the schedule lookup by a specific ID endpoint. - name: transactions description: The transaction object represents the transactions processed on the Hedera network. externalDocs: @@ -1338,7 +1338,7 @@ tags: externalDocs: url: https://docs.hedera.com/guides/docs/mirror-node-api/cryptocurrency-api#topic-messages - name: tokens - description: The tokens object represents the information associated with a token entity and returns a list of token information. + description: The tokens object represents the information associated with a token entity and returns a list of token information.The tokens list endpoint is cached and not updated as frequently as the token lookup by a specific ID. info: title: Hedera Mirror Node REST API version: 0.113.0-SNAPSHOT diff --git a/hedera-mirror-rest/config/application.yml b/hedera-mirror-rest/config/application.yml index aee1cbb029c..cf6b696dd0a 100644 --- a/hedera-mirror-rest/config/application.yml +++ b/hedera-mirror-rest/config/application.yml @@ -88,14 +88,19 @@ hedera: headers: default: { "cache-control": "public, max-age=1" } path: + /api/v1/accounts: { "cache-control": "public, max-age=10" } /api/v1/accounts/:idOrAliasOrEvmAddress: { "cache-control": "public, max-age=2" } /api/v1/accounts/:idOrAliasOrEvmAddress/rewards: { "cache-control": "public, max-age=60" } /api/v1/blocks/:hashOrNumber: { "cache-control": "public, max-age=600" } + /api/v1/contracts: { "cache-control": "public, max-age=10" } /api/v1/contracts/:contractId/results/:consensusTimestamp([0-9.]+): { "cache-control": "public, max-age=600" } + /api/v1/contracts/results: { "cache-control": "public, max-age=10" } + /api/v1/contracts/results/logs: + { "cache-control": "public, max-age=10" } /api/v1/contracts/results/:transactionIdOrHash: { "cache-control": "public, max-age=600" } /api/v1/contracts/results/:transactionIdOrHash/actions: @@ -106,6 +111,8 @@ hedera: /api/v1/network/nodes: { "cache-control": "public, max-age=60" } /api/v1/network/stake: { "cache-control": "public, max-age=60" } /api/v1/network/supply: { "cache-control": "public, max-age=60" } + /api/v1/schedules: { "cache-control": "public, max-age=10" } + /api/v1/tokens: { "cache-control": "public, max-age=10" } /api/v1/tokens/:tokenId: { "cache-control": "public, max-age=5" } /api/v1/topics/:topicId/messages/:sequenceNumber: { "cache-control": "public, max-age=600" }