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

perf: better caching of current round details #147

Merged
merged 5 commits into from
Nov 22, 2023
Merged

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Nov 22, 2023

Rework the implementation of GET /rounds/current to redirect to a permalink GET /rounds/meridian/{addr}/{round}. This allows us to cache better the data queried from our database.

  1. The redirection logic does not need the database; it builds the new location using in-memory data.

    In the future, we can rework spark-checker to determine the current round locally by querying the on-chain state of the Meridian contract.

  2. The response for the permalink for a given meridian round is immutable and, therefore, can be cached forever. If all works out as expected, we should see only one request per round, and the CDN cache will take care of the rest.

I have also improved the database schema to store the meridian contract address and round index in spark_rounds in order to enable fast lookup of Spark rounds from Meridian rounds,

This PR supersedes and closes #143

Links:

- Store meridian contract address and round index in `spark_rounds`.
- Rework `getMeridianRoundDetails` to use these new columns for lookup
- Rework `getMeridianRoundDetails` to enable long caching for immutable
  content (the round details)

Signed-off-by: Miroslav Bajtoš <[email protected]>
Rework the implementation of `GET /rounds/current` to redirect to
a permalink `GET /rounds/meridian/{addr}/{round}`. This allows us
to better cache the data queried from our database.

1. The redirection logic does not need the database, it builds the
   new location using in-memory data.

   In the future, we can rework spark-checker to determine the current
   round locally by querying the on-chain state of the Meridian
   contract.

2. The response for the permalink for a given meridian round
   is immutable and therefore can be cached forever. If all works out
   as expected, we should see only one request per each round, and
   the CDN cache will take care of the rest.

Signed-off-by: Miroslav Bajtoš <[email protected]>
@bajtos bajtos requested a review from juliangruber November 22, 2023 10:16
Copy link
Member

@juliangruber juliangruber left a comment

Choose a reason for hiding this comment

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

great work!

index.js Outdated Show resolved Hide resolved
Co-authored-by: Julian Gruber <[email protected]>
@bajtos bajtos merged commit e163962 into main Nov 22, 2023
8 checks passed
@bajtos bajtos deleted the cache-current-round branch November 22, 2023 12:09
bajtos added a commit that referenced this pull request Nov 22, 2023
Deployment of #147 is failing
because at startup, we are updating `spark_rounds` table with
`meridian_contract` and `meridian_round` before running the database schema
migration.

This commit changes the initialisation order: db migrations first and
everything else afterwards.

Signed-off-by: Miroslav Bajtoš <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ done
Development

Successfully merging this pull request may close these issues.

2 participants