-
Notifications
You must be signed in to change notification settings - Fork 16
Fix/registrar actions slowness #1870
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
Open
shrugs
wants to merge
4
commits into
main
Choose a base branch
from
fix/registrar-actions-slowness
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+133
−109
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
409e07c
checkpoint: add otel tracing, remove subgraph_domains join in slow co…
shrugs 1c05d0d
fix: conditionally join subregistries as needed
shrugs 3688f95
fix: actually keep the join for correctness
shrugs 9a5d016
fix: improper invariant caught by bot
shrugs 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
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
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,3 +1,4 @@ | ||
| import { trace } from "@opentelemetry/api"; | ||
| import { and, count, desc, eq, gte, isNotNull, lte, not, type SQL } from "drizzle-orm/sql"; | ||
|
|
||
| import { | ||
|
|
@@ -21,6 +22,9 @@ import { | |
| } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| import { ensDb, ensIndexerSchema } from "@/lib/ensdb/singleton"; | ||
| import { withSpanAsync } from "@/lib/instrumentation/auto-span"; | ||
|
|
||
| const tracer = trace.getTracer("registrar-actions"); | ||
|
|
||
| /** | ||
| * Build SQL for order clause from provided order param. | ||
|
|
@@ -97,74 +101,78 @@ interface FindRegistrarActionsOptions { | |
| export async function _countRegistrarActions( | ||
| filters: RegistrarActionsFilter[] | undefined, | ||
| ): Promise<number> { | ||
| const countQuery = ensDb | ||
| .select({ | ||
| count: count(), | ||
| }) | ||
| .from(ensIndexerSchema.registrarActions) | ||
| // join Registration Lifecycles associated with Registrar Actions | ||
| .innerJoin( | ||
| ensIndexerSchema.registrationLifecycles, | ||
| eq(ensIndexerSchema.registrarActions.node, ensIndexerSchema.registrationLifecycles.node), | ||
| ) | ||
| // join Domains associated with Registration Lifecycles | ||
| .innerJoin( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removes the unnecessary join on domains, not needed for count |
||
| ensIndexerSchema.subgraph_domain, | ||
| eq(ensIndexerSchema.registrationLifecycles.node, ensIndexerSchema.subgraph_domain.id), | ||
| ) | ||
| // join Subregistries associated with Registration Lifecycles | ||
| .innerJoin( | ||
| ensIndexerSchema.subregistries, | ||
| eq( | ||
| ensIndexerSchema.registrationLifecycles.subregistryId, | ||
| ensIndexerSchema.subregistries.subregistryId, | ||
| ), | ||
| ) | ||
| .where(and(...buildWhereClause(filters))); | ||
|
|
||
| const result = await countQuery; | ||
| return result[0].count; | ||
| return withSpanAsync( | ||
| tracer, | ||
| "registrarActions.count", | ||
| { filterCount: filters?.length ?? 0 }, | ||
| async () => { | ||
| const result = await ensDb | ||
| .select({ count: count() }) | ||
| .from(ensIndexerSchema.registrarActions) | ||
| .innerJoin( | ||
| ensIndexerSchema.registrationLifecycles, | ||
| eq(ensIndexerSchema.registrarActions.node, ensIndexerSchema.registrationLifecycles.node), | ||
| ) | ||
| .innerJoin( | ||
| ensIndexerSchema.subregistries, | ||
| eq( | ||
| ensIndexerSchema.registrationLifecycles.subregistryId, | ||
| ensIndexerSchema.subregistries.subregistryId, | ||
| ), | ||
| ) | ||
| .where(and(...buildWhereClause(filters))); | ||
shrugs marked this conversation as resolved.
Show resolved
Hide resolved
shrugs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return result[0].count; | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Internal function which executes a single query to get all data required to | ||
| * build a list of {@link NamedRegistrarAction} objects. | ||
| */ | ||
| export async function _findRegistrarActions(options: FindRegistrarActionsOptions) { | ||
| const query = ensDb | ||
| .select({ | ||
| registrarActions: ensIndexerSchema.registrarActions, | ||
| registrationLifecycles: ensIndexerSchema.registrationLifecycles, | ||
| subregistries: ensIndexerSchema.subregistries, | ||
| domain: ensIndexerSchema.subgraph_domain, | ||
| }) | ||
| .from(ensIndexerSchema.registrarActions) | ||
| // join Registration Lifecycles associated with Registrar Actions | ||
| .innerJoin( | ||
| ensIndexerSchema.registrationLifecycles, | ||
| eq(ensIndexerSchema.registrarActions.node, ensIndexerSchema.registrationLifecycles.node), | ||
| ) | ||
| // join Domains associated with Registration Lifecycles | ||
| .innerJoin( | ||
| ensIndexerSchema.subgraph_domain, | ||
| eq(ensIndexerSchema.registrationLifecycles.node, ensIndexerSchema.subgraph_domain.id), | ||
| ) | ||
| // join Subregistries associated with Registration Lifecycles | ||
| .innerJoin( | ||
| ensIndexerSchema.subregistries, | ||
| eq( | ||
| ensIndexerSchema.registrationLifecycles.subregistryId, | ||
| ensIndexerSchema.subregistries.subregistryId, | ||
| ), | ||
| ) | ||
| .where(and(...buildWhereClause(options.filters))) | ||
| .orderBy(buildOrderByClause(options.orderBy)) | ||
| .limit(options.limit) | ||
| .offset(options.offset); | ||
|
|
||
| const records = await query; | ||
|
|
||
| return records; | ||
| return withSpanAsync( | ||
| tracer, | ||
| "registrarActions.find", | ||
| { | ||
| filterCount: options.filters?.length ?? 0, | ||
| orderBy: options.orderBy, | ||
| limit: options.limit, | ||
| offset: options.offset, | ||
| }, | ||
| () => | ||
| ensDb | ||
| .select({ | ||
| registrarActions: ensIndexerSchema.registrarActions, | ||
| registrationLifecycles: ensIndexerSchema.registrationLifecycles, | ||
| subregistries: ensIndexerSchema.subregistries, | ||
| domain: ensIndexerSchema.subgraph_domain, | ||
| }) | ||
| .from(ensIndexerSchema.registrarActions) | ||
| // join Registration Lifecycles associated with Registrar Actions | ||
| .innerJoin( | ||
| ensIndexerSchema.registrationLifecycles, | ||
| eq(ensIndexerSchema.registrarActions.node, ensIndexerSchema.registrationLifecycles.node), | ||
| ) | ||
| // join Domains associated with Registration Lifecycles | ||
| .innerJoin( | ||
| ensIndexerSchema.subgraph_domain, | ||
| eq(ensIndexerSchema.registrationLifecycles.node, ensIndexerSchema.subgraph_domain.id), | ||
| ) | ||
| // join Subregistries associated with Registration Lifecycles | ||
| .innerJoin( | ||
| ensIndexerSchema.subregistries, | ||
| eq( | ||
| ensIndexerSchema.registrationLifecycles.subregistryId, | ||
| ensIndexerSchema.subregistries.subregistryId, | ||
| ), | ||
| ) | ||
| .where(and(...buildWhereClause(options.filters))) | ||
| .orderBy(buildOrderByClause(options.orderBy)) | ||
| .limit(options.limit) | ||
| .offset(options.offset), | ||
| ); | ||
shrugs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| type MapToNamedRegistrarActionArgs = Awaited<ReturnType<typeof _findRegistrarActions>>[0]; | ||
|
|
@@ -176,7 +184,7 @@ type MapToNamedRegistrarActionArgs = Awaited<ReturnType<typeof _findRegistrarAct | |
| */ | ||
| function _mapToNamedRegistrarAction(record: MapToNamedRegistrarActionArgs): NamedRegistrarAction { | ||
| // Invariant: The FQDN `name` of the Domain associated with the `node` must exist. | ||
| if (!record.domain.name === null) { | ||
| if (record.domain.name === null) { | ||
| throw new Error(`Domain 'name' must exists for '${record.registrationLifecycles.node}' node.`); | ||
shrugs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
|
|
||
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.