-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Twenty config core implementation #11595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…d add migration file
…as the number of env vars in config variables file
…fig-core-implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
(updates since last review)
Based on the recent changes and previous reviews, I'll focus on the most significant updates to the configuration system:
This PR enhances the configuration system with improved caching and initialization handling.
- Added
ConfigInitializationState
enum to track configuration loading states (NOT_INITIALIZED, INITIALIZING, INITIALIZED, FAILED) - Implemented
ConfigSource
enum to properly identify configuration origins (ENVIRONMENT, DATABASE, DEFAULT) - Added proper handling of environment-only variables through
isEnvOnlyConfigVar
utility - Improved type safety with
ConfigVariableType
andConfigVariableOptions
types - Added basic validation utilities in
apply-basic-validators.util.ts
for different data types
The changes improve the configuration system's reliability through better state management and type validation while maintaining clear separation between environment and database configurations.
33 file(s) reviewed, 10 comment(s)
Edit PR Review Bot Settings | Greptile
@@ -78,4 +78,4 @@ FRONTEND_URL=http://localhost:3001 | |||
# CLOUDFLARE_WEBHOOK_SECRET= | |||
# IS_CONFIG_VARIABLES_IN_DB_ENABLED=false | |||
# ANALYTICS_ENABLED= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: ANALYTICS_ENABLED is empty but should have a default boolean value (true/false)
packages/twenty-server/src/engine/core-modules/twenty-config/cache/config-cache.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts
Show resolved
Hide resolved
...erver/src/engine/core-modules/twenty-config/drivers/__tests__/database-config.driver.spec.ts
Outdated
Show resolved
Hide resolved
@Cron(`0 */${CONFIG_VARIABLES_REFRESH_INTERVAL_MINUTES} * * * *`) | ||
async refreshExpiredCache(): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Cron job could start before initialization is complete. Consider adding initialization check.
this.logger.debug( | ||
`Fetching config for ${key as string} in database: ${result?.value}`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Logging sensitive configuration values could expose secrets in logs
this.logger.debug( | |
`Fetching config for ${key as string} in database: ${result?.value}`, | |
); | |
this.logger.debug( | |
`Fetching config for ${key as string}`, | |
); |
if (typeof value === 'number') { | ||
return value !== 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider handling NaN, Infinity, and -Infinity explicitly in number conversion
provide: TwentyConfigService, | ||
useValue: {}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Empty mock object for TwentyConfigService may be insufficient. Consider adding necessary mock methods/properties that the service actually uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements core configuration functionality along with several refactorings and improvements for the Twenty config system, addressing an issue raised in core-team-issues#760. Key changes include:
- Introducing a new enum (ConfigInitializationState) and new interfaces/driver implementations for database- and environment-backed configuration.
- Refactoring config metadata decorators and removing legacy cast decorators, with corresponding updates to conversion services and tests.
- Adding caching support with a dedicated ConfigCacheService and comprehensive unit tests.
Reviewed Changes
Copilot reviewed 34 out of 35 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
packages/twenty-server/src/engine/core-modules/twenty-config/enums/config-initialization-state.enum.ts | Adds a new enum for representing configuration initialization states. |
packages/twenty-server/src/engine/core-modules/twenty-config/drivers/interfaces/database-config-driver.interface.ts | Introduces an interface for database config drivers with new methods. |
packages/twenty-server/src/engine/core-modules/twenty-config/drivers/environment-config.driver.ts & database-config.driver.ts | Implements environment and database drivers with logging, error handling, and refresh scheduling. |
packages/twenty-server/src/engine/core-modules/twenty-config/decorators/config-variables-metadata.decorator.ts | Updates the metadata decorator to support new options (isEnvOnly, type, options) and applies basic validators. |
packages/twenty-server/src/engine/core-modules/twenty-config/conversion/config-value-converter.service.ts & spec | Adds a service for converting values between DB and app representations with unit tests. |
packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts | Refactors config variable definitions to use type metadata instead of legacy cast decorators. |
packages/twenty-server/src/engine/core-modules/twenty-config/cache/config-cache.service.ts & spec | Implements a cache service for config values with TTL and negative cache support. |
packages/twenty-server/src/engine/core-modules/file/* | Cleans up imports by removing unused TwentyConfigService injections. |
Files not reviewed (1)
- packages/twenty-server/package.json: Language not supported
Comments suppressed due to low confidence (1)
packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts:42
- The removal of legacy cast decorators like @CastToBoolean() may lead to unexpected transformation behavior if the new metadata-based validation does not fully replicate the previous behavior. Please verify that the new type metadata and validators cover all transformation scenarios previously handled by the cast decorators.
- @CastToBoolean()
packages/twenty-server/src/engine/core-modules/twenty-config/drivers/database-config.driver.ts
Outdated
Show resolved
Hide resolved
2eaee68
to
8fef8d1
Compare
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:21544 This environment will automatically shut down when the PR is closed or after 5 hours. |
cacheKeys: string[]; | ||
} { | ||
return { | ||
positiveEntries: this.foundConfigValuesCache.size, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get rid of this positive/negative linguo and stick to found/missing you already use
closes twentyhq/core-team-issues#760