Skip to content

Fix: build sanitise schema per item to restore subclass dispatch#99

Closed
taylortom wants to merge 1 commit intomasterfrom
fix/per-item-sanitise-schema
Closed

Fix: build sanitise schema per item to restore subclass dispatch#99
taylortom wants to merge 1 commit intomasterfrom
fix/per-item-sanitise-schema

Conversation

@taylortom
Copy link
Copy Markdown
Collaborator

Fix

  • Restore the per-item getSchema call inside sanitise() so subclasses that override getSchema to dispatch on the data argument (notably ContentModule) get the right schema for each item.

Background

PR #97 hoisted the getSchema call out of the per-item loop on the basis that getSchema is idempotent for a given schemaName. That holds for AbstractApiModule.getSchema but not for subclasses that override it to vary by data — ContentModule.getSchema returns a different schema per content type / _component / enabled-plugin set.

With the hoisted call, ContentModule.getSchema received the array as its data argument, fell back to the base content schema, and dropped all component-specific and extension fields when sanitising GET responses. Concretely, GETting a graphic component returned only base fields — _graphic, _vanilla, _pageLevelProgress etc. were stripped, so the editor lost the asset thumbnail on revisit.

PR #97's stated rationale ("schema.sanitise() is now synchronous") is correct but didn't actually motivate removing the loop — the await in the previous code was for getSchema (still async), not sanitise.

Cost

Bounded by:

  • AbstractApiModule.find/findOne — already DataCached (AbstractApiModule.js:650).
  • ContentModule._schemaCache — already keys built schemas by schemaName + enabledPlugins.

Worst case for a 100-item batch with 10 unique component types: ~11 DB hits and ~10 schema builds on a cold cache; subsequent items hit the cache. Same shape as pre-PR-97 behaviour.

Testing

  1. npm test
  2. With adapt-authoring-content, GET /api/content/<componentId> for a graphic component and confirm _graphic, _vanilla, _pageLevelProgress, etc. appear in the response.

PR #97 hoisted the getSchema call out of the per-item loop on the
basis that getSchema is idempotent for a given schemaName. That holds
for the base implementation here but not for subclasses that override
getSchema to dispatch on the item itself (notably ContentModule, which
returns a different schema per content type / component / enabled-
plugin set).

With the hoisted call, ContentModule's getSchema received the array as
its data argument, fell back to the base content schema, and dropped
all component-specific and extension fields when sanitising GET
responses. Restoring per-item getSchema fixes the dispatch.

The cost is bounded by DataCache (find/findOne) and ContentModule's
own _schemaCache, which between them keep extra DB hits to one per
unique component type per request.
@taylortom taylortom closed this Apr 30, 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