Refactor schema workflows to avoid extra operations and duplicate sch… #321
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.
Problem
Duplicate schema fetches and tight coupling between SchemaRetriever, GetSchemaTaskManager, and SchemaStore via callbacks and direct datastore access.
Solution: Architectural Simplification
SchemaStore (New API Layer)
• Added controlled getters: getPublicSchemas(), getSamSchemas(), getPrivateSchemas(), getPublicSchemaRegions()
• Added age tracking: getSamSchemaAge(), getPublicSchemasMaxAge()
• Smart caching in get(): only rebuilds combined schemas when region changes
• invalidate() method clears cache when underlying data updates
• Eliminates direct datastore access from other components
GetSchemaTaskManager (Simplified)
• Removed: Settings subscription, automatic background timers (10s/1hr), onSchemaUpdate callback, profile tracking, Closeable interface
• Changed: Now directly calls schemas.invalidate() after private/SAM tasks complete
• Added: processedRegions Set for deduplication (tracks regions ever processed)
SchemaRetriever (Delegated)
• Added explicit initialize() method that checks schema staleness (7-day threshold)
• Delegates to GetSchemaTaskManager instead of managing callbacks
• Preserves firstCreatedMs when refreshing stale schemas
Key Behaviors
Startup: Constructor immediately calls addTask(defaultRegion), then initialize() checks all cached schemas for staleness and triggers refreshes
Caching: Combined schemas cached by region+profile key, only rebuilt on region change or explicit invalidation
Fallback: Requesting unavailable region returns last available region's schemas (graceful degradation)
Deduplication: processedRegions Set prevents re-adding same region, but never clears entries
Test Changes
• New comprehensive SchemaStore.test.ts
• Modernized tests using sinon stubs instead of vi mocks
• Better async handling with waitFor() helper