Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generated a custom key for the cache in blocks endpoint #1381

Merged
merged 2 commits into from
Jan 12, 2024

Conversation

Imod7
Copy link
Contributor

@Imod7 Imod7 commented Jan 11, 2024

Issue

When we request a block in Sidecar with a query param set to a specific value, e.g. :
/blocks/1820744?extrinsicDocs=false : return block and show the docs in each extrinsic
and right away I request again the same block but now with the query param set to a different value, e.g. :
/blocks/1820744?extrinsicDocs=true : return block and do not show the docs in each extrinsic

the response is not updated so it still doesn't show me the docs in each extrinsic.

Root Cause

This happens because of how we cache the response. Wen we cache the block here we set the key in the cache "array" equal to the block hash. So when we request again the same block it will only check here if it finds this block hash and it will ignore the different query params. It will then find that this block was requested before and it will return the saved response. The problem is that this saved response has extrinsicDocs false so it will still not show me the docs.

Proposed Solution

Create a key that is a combination of the block hash (request param) and the query params of the request. This key will then be used to save/retrieve responses to/from the cache.

  • The query params values were concatenated as 0 or 1s (since they are boolean indicating false or truevalues).

  • For the generation of the key, only the query params

    • eventDocs
    • extrinsicDocs
    • checkFinalized,
    • noFees

    are used since those are the ones that can be changed by the user. The options queryFinalizedHead and omitFinalizedTag are not included since they depend on the params set above.

Testing

This solution was tested while running sidecar connected to Polkadot. For example, the requested block :

  • http://127.0.0.1:8080/blocks/1820747?extrinsicDocs=false&eventDocs=true
    is updated when changing the query param extrinsicDocs and eventDocs to different boolean values.

@Imod7 Imod7 requested a review from a team as a code owner January 11, 2024 15:33
Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM great job!

Copy link
Contributor

@bee344 bee344 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool addition :)

@Imod7 Imod7 merged commit 17cbd2c into master Jan 12, 2024
17 checks passed
@Imod7 Imod7 deleted the domi-fix-cache-key branch January 12, 2024 05:23
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants