Skip to content

ADR-014 Add breadth-first link expanders and dependency resolvers#2

Open
richardTowers wants to merge 2 commits into
adr-014-1-groundworkfrom
adr-014-2-bfs-impl
Open

ADR-014 Add breadth-first link expanders and dependency resolvers#2
richardTowers wants to merge 2 commits into
adr-014-1-groundworkfrom
adr-014-2-bfs-impl

Conversation

@richardTowers

Copy link
Copy Markdown
Owner

This is the second in the series of ADR-014 PRs, starting with alphagov#4097

richardTowers and others added 2 commits June 10, 2026 12:50
LinkExpansion::BreadthFirstExpander reproduces links_with_content using
the shared batch SQL queries, walking the link graph breadth-first (one
forward + one reverse query per level) instead of the current depth-first
one-query-per-node traversal. LinkExpansion#links_with_content dispatches
to it when LINK_EXPANSION_IMPLEMENTATION=breadth-first (default: depth-first).

Reproduces existing behaviour exactly: per-path ancestor cycle pruning
(not a global visited set), root link-type discovery, edition links only
at the root (edition_id: NULL at child levels), reverse re-keying
including the role_appointments -> person/role fan-out, auto_reverse_link,
and the withdrawn override for SQL-sourced editions.

Adds a link_source discriminator column to both SQL queries so the expander can
identify editions reached via edition links: existing code never expands their
children ("no nested edition links") and excludes edition-sourced reverse links
at child levels. The column is additive and ignored by the GraphQL dataloaders.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
DependencyResolution::BreadthFirstResolver resolves dependent content_ids
breadth-first, mirroring the link expander with directions swapped.
DependencyResolution#dependencies dispatches to it when
LINK_EXPANSION_IMPLEMENTATION=breadth-first (default: depth-first), the
same flag and values the expander uses.

Unlike link expansion, dependency resolution returns a dependent's
content_id whether or not it has a renderable edition, so the resolver
reads the links table directly rather than the edition-joining batch SQL.
Edition links only matter at the root (child levels follow link set links
only, as the depth-first implementation does), so the root reuses the
existing Queries::Links / Queries::EditionLinks and the recursive levels
batch plain links-table reads (one incoming + one outgoing query per
level). This keeps spec/integration/dependency_resolution_spec.rb passing
unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@richardTowers richardTowers changed the title Add breadth-first link expanders and dependency resolvers ADR-014 Add breadth-first link expanders and dependency resolvers Jun 10, 2026
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.

1 participant