From 273169264eab988bb49e48529c38265c8f71ed5b Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 07:26:59 +0100 Subject: [PATCH] ax(mining): rename db-prefixed fields to full databaseEnabled/databaseRetention MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pkg/mining/manager.go | 42 +++++++++++++++++++++--------------------- pkg/mining/service.go | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pkg/mining/manager.go b/pkg/mining/manager.go index b03a670..d98ebb2 100644 --- a/pkg/mining/manager.go +++ b/pkg/mining/manager.go @@ -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 } diff --git a/pkg/mining/service.go b/pkg/mining/service.go index 5f87b5a..747ab26 100644 --- a/pkg/mining/service.go +++ b/pkg/mining/service.go @@ -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 }