Skip to content

Commit 5682d37

Browse files
committed
fix: union for distinct cte
1 parent 29f873b commit 5682d37

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

apps/ensapi/src/graphql-api/lib/canonical-registries-cte.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ import { db } from "@/lib/db";
99

1010
/**
1111
* The maximum depth to traverse the ENSv2 namegraph in order to construct the set of Canonical
12-
* Registries. While technically not necessary (as a doubly-linked directed graph cannot include
13-
* cycles) this avoids the possibility of an infinite runaway query in the event that the indexed
14-
* namegraph is somehow corrupted or otherwise introduces a canonical cycle.
12+
* Registries.
13+
*
14+
* Note that the set of Canonical Registries in the ENSv2 Namegraph is a _tree_, enforced by the
15+
* requirement that each Registry maintain a reverse-pointer to its Canonical Domain, a form of
16+
* 'edge authentication': if the reverse-pointer doesn't agree with the forward-pointer, the edge
17+
* is not traversed, making cycles within the direced graph impossible.
18+
*
19+
* So while technically not necessary, including the depth constraint avoids the possibility of an
20+
* infinite runaway query in the event that the indexed namegraph is somehow corrupted or otherwise
21+
* introduces a canonical cycle.
1522
*/
1623
const CANONICAL_REGISTRIES_MAX_DEPTH = 16;
1724

@@ -29,7 +36,7 @@ export const getCanonicalRegistriesCTE = () =>
2936
sql`(
3037
WITH RECURSIVE canonical_registries AS (
3138
SELECT ${getENSv2RootRegistryId(config.namespace)}::text AS registry_id, 0 AS depth
32-
UNION
39+
UNION ALL
3340
SELECT rcd.registry_id, cr.depth + 1
3441
FROM ${schema.registryCanonicalDomain} rcd
3542
JOIN ${schema.v2Domain} parent ON parent.id = rcd.domain_id AND parent.subregistry_id = rcd.registry_id

0 commit comments

Comments
 (0)