ax(mining): rename db-prefixed fields to full databaseEnabled/databaseRetention

AX Principle 1 — predictable names over short names. The Manager struct
fields dbEnabled and dbRetention used the db abbreviation which requires
context to decode. Renamed to databaseEnabled and databaseRetention across
manager.go and the single service.go callsite. No behaviour change.

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 07:26:59 +01:00
parent e707710e9d
commit 273169264e
No known key found for this signature in database
GPG key ID: AF404715446AEB41
2 changed files with 22 additions and 22 deletions

View file

@ -35,8 +35,8 @@ type Manager struct {
stopChan chan struct{}
stopOnce sync.Once
waitGroup sync.WaitGroup
dbEnabled bool
dbRetention int
databaseEnabled bool
databaseRetention int
eventHub *EventHub
eventHubMu sync.RWMutex // Separate mutex for eventHub to avoid deadlock with main mu
}
@ -97,29 +97,29 @@ func (m *Manager) initDatabase() {
return
}
m.dbEnabled = cfg.Database.Enabled
m.dbRetention = cfg.Database.RetentionDays
if m.dbRetention == 0 {
m.dbRetention = 30
m.databaseEnabled = cfg.Database.Enabled
m.databaseRetention = cfg.Database.RetentionDays
if m.databaseRetention == 0 {
m.databaseRetention = 30
}
if !m.dbEnabled {
if !m.databaseEnabled {
logging.Debug("database persistence is disabled")
return
}
dbCfg := database.Config{
Enabled: true,
RetentionDays: m.dbRetention,
RetentionDays: m.databaseRetention,
}
if err := database.Initialize(dbCfg); err != nil {
logging.Warn("failed to initialize database", logging.Fields{"error": err})
m.dbEnabled = false
m.databaseEnabled = false
return
}
logging.Info("database persistence enabled", logging.Fields{"retention_days": m.dbRetention})
logging.Info("database persistence enabled", logging.Fields{"retention_days": m.databaseRetention})
// Start periodic cleanup
m.startDBCleanup()
@ -140,14 +140,14 @@ func (m *Manager) startDBCleanup() {
defer ticker.Stop()
// Run initial cleanup
if err := database.Cleanup(m.dbRetention); err != nil {
if err := database.Cleanup(m.databaseRetention); err != nil {
logging.Warn("database cleanup failed", logging.Fields{"error": err})
}
for {
select {
case <-ticker.C:
if err := database.Cleanup(m.dbRetention); err != nil {
if err := database.Cleanup(m.databaseRetention); err != nil {
logging.Warn("database cleanup failed", logging.Fields{"error": err})
}
case <-m.stopChan:
@ -569,7 +569,7 @@ func (m *Manager) collectMinerStats() {
// Use the miner's GetType() method for proper type identification
miners = append(miners, minerInfo{miner: miner, minerType: miner.GetType()})
}
dbEnabled := m.dbEnabled // Copy to avoid holding lock
databaseEnabled := m.databaseEnabled // Copy to avoid holding lock
m.mu.RUnlock()
now := time.Now()
@ -588,7 +588,7 @@ func (m *Manager) collectMinerStats() {
})
}
}()
m.collectSingleMinerStats(miner, minerType, now, dbEnabled)
m.collectSingleMinerStats(miner, minerType, now, databaseEnabled)
}(mi.miner, mi.minerType)
}
wg.Wait()
@ -602,7 +602,7 @@ const statsRetryDelay = 500 * time.Millisecond
// collectSingleMinerStats collects stats from a single miner with retry logic.
// This is called concurrently for each miner.
func (m *Manager) collectSingleMinerStats(miner Miner, minerType string, now time.Time, dbEnabled bool) {
func (m *Manager) collectSingleMinerStats(miner Miner, minerType string, now time.Time, databaseEnabled bool) {
minerName := miner.GetName()
var stats *PerformanceMetrics
@ -654,7 +654,7 @@ func (m *Manager) collectSingleMinerStats(miner Miner, minerType string, now tim
miner.ReduceHashrateHistory(now)
// Persist to database if enabled
if dbEnabled {
if databaseEnabled {
dbPoint := database.HashratePoint{
Timestamp: point.Timestamp,
Hashrate: point.Hashrate,
@ -723,7 +723,7 @@ func (m *Manager) Stop() {
}
// Close the database
if m.dbEnabled {
if m.databaseEnabled {
if err := database.Close(); err != nil {
logging.Warn("failed to close database", logging.Fields{"error": err})
}
@ -733,7 +733,7 @@ func (m *Manager) Stop() {
// GetMinerHistoricalStats returns historical stats from the database for a miner.
func (m *Manager) GetMinerHistoricalStats(minerName string) (*database.HashrateStats, error) {
if !m.dbEnabled {
if !m.databaseEnabled {
return nil, fmt.Errorf("database persistence is disabled")
}
return database.GetHashrateStats(minerName)
@ -741,7 +741,7 @@ func (m *Manager) GetMinerHistoricalStats(minerName string) (*database.HashrateS
// GetMinerHistoricalHashrate returns historical hashrate data from the database.
func (m *Manager) GetMinerHistoricalHashrate(minerName string, since, until time.Time) ([]HashratePoint, error) {
if !m.dbEnabled {
if !m.databaseEnabled {
return nil, fmt.Errorf("database persistence is disabled")
}
@ -763,7 +763,7 @@ func (m *Manager) GetMinerHistoricalHashrate(minerName string, since, until time
// GetAllMinerHistoricalStats returns historical stats for all miners from the database.
func (m *Manager) GetAllMinerHistoricalStats() ([]database.HashrateStats, error) {
if !m.dbEnabled {
if !m.databaseEnabled {
return nil, fmt.Errorf("database persistence is disabled")
}
return database.GetAllMinerStats()
@ -771,5 +771,5 @@ func (m *Manager) GetAllMinerHistoricalStats() ([]database.HashrateStats, error)
// IsDatabaseEnabled returns whether database persistence is enabled.
func (m *Manager) IsDatabaseEnabled() bool {
return m.dbEnabled
return m.databaseEnabled
}

View file

@ -1278,7 +1278,7 @@ func (s *Service) handleHistoryStatus(c *gin.Context) {
if manager, ok := s.Manager.(*Manager); ok {
c.JSON(http.StatusOK, gin.H{
"enabled": manager.IsDatabaseEnabled(),
"retentionDays": manager.dbRetention,
"retentionDays": manager.databaseRetention,
})
return
}