Skip to content

Memoize sourced_from update target resolution on Results - #1342

Merged
ellisandrews-toast merged 1 commit into
mainfrom
OLAP-741-memoize-sourced-from-update-targets
Aug 13, 2026
Merged

Memoize sourced_from update target resolution on Results#1342
ellisandrews-toast merged 1 commit into
mainfrom
OLAP-741-memoize-sourced-from-update-targets

Conversation

@ellisandrews-toast

Copy link
Copy Markdown
Collaborator

Summary

Pure refactor, no behavior change: extracts the inline Indexing::SourcedFromUpdateTargetsResolver.new(state).resolve call in Results#build_runtime_metadata into a memoized Results#sourced_update_targets_by_source_type_name method, following the existing derived_indexing_type_names pattern.

Motivation

First step toward #1273. Supporting unindexed sourced_from source types requires the JSON schema event envelope (generated in elasticgraph-json_ingestion) to include source type names in its type enum — and that set is exactly the keys of this resolver's result. Memoizing it on Results lets a follow-up PR consume it from ResultsExtension (the same way derived_indexing_type_names is consumed today) without running a second resolver pass.

Notes

build_runtime_metadata still invokes the resolver eagerly before materializing all_types — the ordering matters so that sourced_from validation errors take precedence over errors raised during derived-type generation. A comment now documents this previously-implicit constraint; two existing specs guard it.

@ellisandrews-toast
ellisandrews-toast merged commit aab3a9c into main Aug 13, 2026
37 of 39 checks passed
@ellisandrews-toast
ellisandrews-toast deleted the OLAP-741-memoize-sourced-from-update-targets branch August 13, 2026 13:54
ellisandrews-toast added a commit that referenced this pull request Aug 13, 2026
…es (#1343)

## Summary

Second step toward #1273 (stacked on #1342). Allows an `indexing_only:
true` relationship to reference a non-indexed object type, so that a
`sourced_from` source type will no longer be required to have its own
index.

Relationships serve two distinct jobs today:

1. GraphQL navigation (query time): the generated relationship field
resolves by searching the related type's index. This genuinely requires
the related type to be indexed.
2. `sourced_from` routing (indexing time): the relationship's foreign
key metadata routes source events to the destination type's documents.
The source type's own index is never touched.

The previous validation ("Only root document types can be used in
relations") applied the job-1 requirement to both jobs. This PR scopes
it to job 1: GraphQL-exposed relationships still require an indexed
related type (with an updated error message that explains why), while
`indexing_only: true` relationships may now reference a non-indexed
type.

## New id validation

Allowing non-indexed related types opens a validation gap. "Indexed
types must have an `id` field" is enforced as a side effect of `t.index`
— so until now, source types (being necessarily indexed) always had `id`
guaranteed transitively. A non-indexed source type skips that check
entirely, but relationships join on `id` non-negotiably: the source
event's `id` drives per-source-record version tracking on destination
documents, and nested `sourced_from` matches list elements by `id`.
Without a check, a missing `id` would surface as confusing
ingestion-time failures far from the actual mistake.

This PR adds the corresponding schema-definition-time validation in
`RelationshipResolver`: a non-indexed related type must define an `id`
field, reported with the standard relationship error context. Indexed
related types are unaffected (they're already validated via `t.index`).

## Note on scope

This PR makes such schemas _definable_, but events for a non-indexed
source type are still rejected at ingestion: the event envelope's `type`
enum in `json_schemas.yaml` only includes indexed types. Widening that
to "ingestable types" (indexed types + `sourced_from` source types) is
the next PR in the stack.
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.

2 participants