Refactor storage initialization to reduce code duplication - #1089
Conversation
Persistence setup (PgStorage wiring, Hasura callbacks, ClickHouse sink) was identical for every indexer but lived in codegen'd Generated module. Now PgStorage.makeStorageFromEnv and PgStorage.makePersistenceFromConfig handle this in library code, and Main.start creates persistence from config when not explicitly provided. https://claude.ai/code/session_01K1BtDSAFuEFegzihzFvfhB
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe changes consolidate persistence initialization logic by introducing helper functions in PgStorage ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Config already contains allEntities, no need to pass it separately. https://claude.ai/code/session_01K1BtDSAFuEFegzihzFvfhB
Summary
This PR refactors the storage and persistence initialization logic by extracting common patterns into reusable functions in
PgStorage, eliminating significant code duplication across the codebase.Key Changes
Added new factory functions in PgStorage.res:
makeStorageFromEnv: Creates a storage instance using environment variables, consolidating the logic previously duplicated in generated codemakePersistenceFromConfig: Creates a persistence instance from a config and storage, reducing boilerplateUpdated code generation templates:
makeStorageandcodegenPersistencefunctions from generated codecreateTestIndexerbinding to useconfigWithoutRegistrations.allEntitiesdirectly instead of accessing throughcodegenPersistenceUpdated Main.rs to support optional persistence:
persistenceparameter inMain.startto be optionalPgStorage.makePersistenceFromConfigUpdated test and migration helpers:
Mock.res,DbHelpers.res, andMigrations.resto use the new factory functionsIndexer.Generated.codegenPersistenceto use the new patternMinor formatting improvements:
PgStorage.resfor better readabilityImplementation Details
The refactoring maintains backward compatibility while reducing ~80 lines of duplicated storage initialization code. The new factory functions encapsulate all the environment variable reading and Hasura integration logic that was previously repeated in generated code templates.
https://claude.ai/code/session_01K1BtDSAFuEFegzihzFvfhB
Summary by CodeRabbit
Release Notes