Skip to content

Conversation

@satyakigh
Copy link
Collaborator

@satyakigh satyakigh commented Nov 28, 2025

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

@satyakigh satyakigh requested a review from a team as a code owner November 28, 2025 20:22
@satyakigh satyakigh force-pushed the schema-refactor branch 3 times, most recently from 56ac661 to 211511b Compare December 3, 2025 16:05
chrisqm-dev
chrisqm-dev previously approved these changes Dec 3, 2025
@satyakigh satyakigh merged commit 8e74540 into main Dec 3, 2025
14 checks passed
@satyakigh satyakigh deleted the schema-refactor branch December 3, 2025 20:47
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.

3 participants