优化结构

This commit is contained in:
Yvan
2026-08-25 16:38:51 +08:00
parent ee179d6b34
commit 001e39da50
9 changed files with 67 additions and 418 deletions
-1
View File
@@ -446,6 +446,5 @@ func (d *Data) reloadConfig(ctx context.Context) error {
if d.storage != nil {
d.storage.Replace(candidateStorage)
}
d.notifyResources()
return nil
}
-27
View File
@@ -46,7 +46,6 @@ func NewIntegrationRuntime(data *Data) *runtimeconfig.Store {
type Data struct {
initMu sync.Mutex
configMu sync.Mutex
resourceMu sync.RWMutex
databaseReady atomic.Bool
gormDB *reloadableDB
redis *reloadableRedis
@@ -65,7 +64,6 @@ type Data struct {
appLogger *slog.Logger
auditLog *dataScopeAuditWriter
catalog module.Catalog
resourceHook func()
}
// DB exposes the active primary database to narrowly scoped data submodules.
@@ -172,30 +170,6 @@ func (d *Data) NamedRedisClients() map[string]redis.UniversalClient {
return result
}
// SetResourceHook registers a composition-root callback invoked after active
// database, Redis, or Mongo handles change. A callback keeps data independent
// from the global package while allowing the root to refresh shared handles.
func (d *Data) SetResourceHook(hook func()) {
if d == nil {
return
}
d.resourceMu.Lock()
d.resourceHook = hook
d.resourceMu.Unlock()
}
func (d *Data) notifyResources() {
if d == nil {
return
}
d.resourceMu.RLock()
hook := d.resourceHook
d.resourceMu.RUnlock()
if hook != nil {
hook()
}
}
func (d *Data) logger() *slog.Logger {
if d != nil && d.appLogger != nil {
return d.appLogger
@@ -467,5 +441,4 @@ func (d *Data) activateDatabase(db *gorm.DB, config *config.Database) {
d.gormDB.replace(db, d.enqueueDataScopeAudit)
d.runtime.UpdateDatabase(config)
d.databaseReady.Store(true)
d.notifyResources()
}
-2
View File
@@ -105,7 +105,6 @@ func (d *Data) PersistRuntimeConfig(ctx context.Context, value *configpkg.Config
if d.storage != nil {
d.storage.Replace(candidateStorage)
}
d.notifyResources()
return nil
}
func (d *Data) ReloadConfig(ctx context.Context) error {
@@ -213,6 +212,5 @@ func (d *Data) InitializeDatabase(ctx context.Context, input *system.DatabaseCon
if d.integrations != nil {
d.integrations.Replace(integrationConfigs)
}
d.notifyResources()
return nil
}