-
Notifications
You must be signed in to change notification settings - Fork 16
Integrate ENSDb SDK into ENSApi #1809
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
45b3ed9
Introduce `DATABASE_SCHEMA` to ENSApi env settings
tk-o 255b969
Create ENSDb Config file
tk-o 2dc7893
Replace fetching data from ENSIndexer Client with ENSDb Client
tk-o d6eb62d
Remove ENSIndexer dependencies from ENSApi
tk-o 5064db7
Remove `ENSINDEXER_URL` env var from ENSApi
tk-o 281f4fb
Update testing suite
tk-o 35f7d22
Merge remote-tracking branch 'origin/main' into feat/integrate-ensdb-…
tk-o 6265901
Apply AI PR feedback
tk-o c7738ec
Update `client` getter to `drizzle` for `EnsDbReader` and `EnsDbWriter`
tk-o 22cc91b
Replace drizzle client and ENSIndexer Schema references in ENSApi
tk-o 3aa85fc
Replace `DATABASE_SCHEMA` env var with `ENSINDEXER_SCHEMA_NAME` for E…
tk-o ee4456c
Update Integration Test Env
tk-o 670f55f
Merge remote-tracking branch 'origin/main' into feat/integrate-ensdb-…
tk-o 43d1adb
Adjust the amount of retires for ENSApi loading ENSIndexer Public Con…
tk-o b8590db
Apply AI PR feedback
tk-o d70d4b3
Update OpenAPI spec file
tk-o 9718ada
docs(changeset): Renamed the `client` getter on `EnsDbReader` class t…
tk-o 5c84b5a
docs(changeset): Updated data source for `EnsIndexerPublicConfig`, fr…
tk-o bbbde56
docs(changeset): Updated data source for Indexing Status snapshot, fr…
tk-o 13eba04
docs(changeset): Updated custom queries for ENSDb to implement data m…
tk-o 3ba2be9
Apply AI PR feedback
tk-o d621877
Merge remote-tracking branch 'origin/main' into feat/integrate-ensdb-…
tk-o e6b2239
Apply suggestions from code review
tk-o 2ccb3dd
Merge remote-tracking branch 'origin/main' into feat/integrate-ensdb-…
tk-o 63cf68a
Rename the `drizzle` getter on `EnsDbReader` class to `ensDb`.
tk-o 32943fc
Reanme `ensDbConnectionString` to `ensDbUrl`
tk-o a8b7f86
Reanme `ensDbConnectionString` to `ensDbUrl`
tk-o ae8cd89
Tweak the indexing status cache settings for ENSApi
tk-o cefbdbb
Applying PR feedback
tk-o c0f97ef
Merge remote-tracking branch 'origin/main' into feat/integrate-ensdb-…
tk-o 383477b
Fix integration tests
tk-o File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@ensnode/ensdb-sdk": minor | ||
| --- | ||
|
|
||
| Renamed the `client` getter on `EnsDbReader` class to `ensDb`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ensapi": minor | ||
| --- | ||
|
|
||
| Updated custom queries for ENSDb to implement data model from ENSDb SDK. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ensapi": minor | ||
| --- | ||
|
|
||
| Decoupled ENSApi from ENSIndexer by updating the data source for `EnsIndexerPublicConfig` from ENSIndexer to ENSDb. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ensapi": minor | ||
| --- | ||
|
|
||
| Decoupled ENSApi from ENSIndexer by updating the data source for Indexing Status snapshots, from ENSIndexer's Indexing Status API route to ENSDb. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,46 @@ | ||
| import config from "@/config"; | ||
|
|
||
| import { | ||
| type CrossChainIndexingStatusSnapshot, | ||
| ENSNodeClient, | ||
| IndexingStatusResponseCodes, | ||
| SWRCache, | ||
| } from "@ensnode/ensnode-sdk"; | ||
| import { EnsNodeMetadataKeys } from "@ensnode/ensdb-sdk"; | ||
| import { type CrossChainIndexingStatusSnapshot, SWRCache } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| import { ensDbClient } from "@/lib/ensdb/singleton"; | ||
| import { makeLogger } from "@/lib/logger"; | ||
|
|
||
| const logger = makeLogger("indexing-status.cache"); | ||
| const client = new ENSNodeClient({ url: config.ensIndexerUrl }); | ||
|
|
||
| export const indexingStatusCache = new SWRCache<CrossChainIndexingStatusSnapshot>({ | ||
| fn: async (_cachedResult) => | ||
| client | ||
| .indexingStatus() // fetch a new indexing status snapshot | ||
| .then((response) => { | ||
| if (response.responseCode !== IndexingStatusResponseCodes.Ok) { | ||
| // An indexing status response was successfully fetched, but the response code contained within the response was not 'ok'. | ||
| ensDbClient | ||
| .getIndexingStatusSnapshot() // get the latest indexing status snapshot | ||
| .then((snapshot) => { | ||
| if (snapshot === undefined) { | ||
| // An indexing status snapshot has not been found in ENSDb yet. | ||
| // This might happen during application startup, i.e. when ENSDb | ||
| // has not yet been populated with the first snapshot. | ||
| // Therefore, throw an error to trigger the subsequent `.catch` handler. | ||
| throw new Error("Received Indexing Status response with responseCode other than 'ok'."); | ||
| throw new Error("Indexing Status snapshot not found in ENSDb yet."); | ||
| } | ||
|
|
||
| logger.info("Fetched Indexing Status to be cached"); | ||
|
|
||
| // The indexing status snapshot has been fetched and successfully validated for caching. | ||
| // Therefore, return it so that this current invocation of `readCache` will: | ||
| // - Replace the currently cached value (if any) with this new value. | ||
| // - Return this non-null value. | ||
| return response.realtimeProjection.snapshot; | ||
| return snapshot; | ||
| }) | ||
| .catch((error) => { | ||
| // Either the indexing status snapshot fetch failed, or the indexing status response was not 'ok'. | ||
| // Either the indexing status snapshot fetch failed, or the indexing status snapshot was not found in ENSDb yet. | ||
| // Therefore, throw an error so that this current invocation of `readCache` will: | ||
| // - Reject the newly fetched response (if any) such that it won't be cached. | ||
| // - Return the most recently cached value from prior invocations, or `null` if no prior invocation successfully cached a value. | ||
| logger.error( | ||
| error, | ||
| "Error occurred while fetching a new indexing status snapshot. The cached indexing status snapshot (if any) will not be updated.", | ||
| `Error occurred while loading Indexing Status snapshot record from ENSNode Metadata table in ENSDb. ` + | ||
| `Where clause applied: ("ensIndexerSchemaName" = "${ensDbClient.ensIndexerSchemaName}", "key" = "${EnsNodeMetadataKeys.EnsIndexerIndexingStatus}"). ` + | ||
| `The cached indexing status snapshot (if any) will not be updated.`, | ||
| ); | ||
| throw error; | ||
| }), | ||
| ttl: 5, // 5 seconds | ||
| proactiveRevalidationInterval: 10, // 10 seconds | ||
| // We need to refresh the indexing status cache very frequently. | ||
| // ENSDb won't have issues handling this frequency of queries. | ||
| ttl: 1, // 1 second | ||
| proactiveRevalidationInterval: 1, // 1 second | ||
| proactivelyInitialize: true, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.