Skip to content

Commit fce7ce7

Browse files
committed
mute DBReadCache ReadOnly messages without debug
1 parent 5d739e3 commit fce7ce7

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

server/settings/dbreadcache.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ func (v *DBReadCache) Get(xPath, name string) []byte {
6060

6161
func (v *DBReadCache) Set(xPath, name string, value []byte) {
6262
if ReadOnly {
63-
log.TLogln("DB.Set: Read-only DB mode!", name)
63+
if IsDebug() {
64+
log.TLogln("DBReadCache.Set: Read-only DB mode!", name)
65+
}
6466
return
6567
}
6668
// Проверяем, не закрыта ли база
6769
if v.dataCache == nil || v.db == nil {
68-
log.TLogln("DB.Set: no dataCache or DB is closed, cannot set", name)
70+
log.TLogln("DBReadCache.Set: no dataCache or DB is closed, cannot set", name)
6971
return
7072
}
7173

@@ -114,12 +116,14 @@ func (v *DBReadCache) List(xPath string) []string {
114116

115117
func (v *DBReadCache) Rem(xPath, name string) {
116118
if ReadOnly {
117-
log.TLogln("DB.Rem: Read-only DB mode!", name)
119+
if IsDebug() {
120+
log.TLogln("DBReadCache.Rem: Read-only DB mode!", name)
121+
}
118122
return
119123
}
120124
// Проверяем, не закрыта ли база
121125
if v.dataCache == nil || v.db == nil {
122-
log.TLogln("DB.Rem: no dataCache or DB is closed, cannot remove", name)
126+
log.TLogln("DBReadCache.Rem: no dataCache or DB is closed, cannot remove", name)
123127
return
124128
}
125129

@@ -140,7 +144,9 @@ func (v *DBReadCache) Rem(xPath, name string) {
140144

141145
func (v *DBReadCache) Clear(xPath string) {
142146
if ReadOnly {
143-
log.TLogln("DB.Clear: Read-only DB mode!", xPath)
147+
if IsDebug() {
148+
log.TLogln("DBReadCache.Clear: Read-only DB mode!", xPath)
149+
}
144150
return
145151
}
146152

server/settings/migrate.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func MigrateViewedFromJson(jsonDB, bboltDB TorrServerDB) error {
147147
func MigrateSingle(source, target TorrServerDB, xpath, name string) (bool, error) {
148148
sourceData := source.Get(xpath, name)
149149
if sourceData == nil {
150-
if getDebug() {
150+
if IsDebug() {
151151
log.TLogln(fmt.Sprintf("No data to migrate for %s/%s", xpath, name))
152152
}
153153
return false, nil
@@ -157,7 +157,7 @@ func MigrateSingle(source, target TorrServerDB, xpath, name string) (bool, error
157157
if targetData != nil {
158158
// Check if already identical
159159
if equal, err := isByteArraysEqualJson(sourceData, targetData); err == nil && equal {
160-
if getDebug() {
160+
if IsDebug() {
161161
log.TLogln(fmt.Sprintf("Skipping %s/%s (already identical)", xpath, name))
162162
}
163163
return false, nil
@@ -166,15 +166,15 @@ func MigrateSingle(source, target TorrServerDB, xpath, name string) (bool, error
166166

167167
// Perform migration
168168
target.Set(xpath, name, sourceData)
169-
if getDebug() {
169+
if IsDebug() {
170170
log.TLogln(fmt.Sprintf("Migrating %s/%s", xpath, name))
171171
}
172172

173173
// Verify migration
174174
if err := verifyMigration(source, target, xpath, name, sourceData); err != nil {
175175
return false, fmt.Errorf("migration verification failed for %s/%s: %w", xpath, name, err)
176176
}
177-
if getDebug() {
177+
if IsDebug() {
178178
log.TLogln(fmt.Sprintf("Successfully migrated %s/%s", xpath, name))
179179
}
180180
return true, nil
@@ -185,7 +185,7 @@ func MigrateSingle(source, target TorrServerDB, xpath, name string) (bool, error
185185
func MigrateAll(source, target TorrServerDB, xpath string) (int, int, error) {
186186
names := source.List(xpath)
187187
if len(names) == 0 {
188-
if getDebug() {
188+
if IsDebug() {
189189
log.TLogln(fmt.Sprintf("No entries to migrate for %s", xpath))
190190
}
191191
return 0, 0, nil
@@ -194,14 +194,14 @@ func MigrateAll(source, target TorrServerDB, xpath string) (int, int, error) {
194194
migratedCount := 0
195195
skippedCount := 0
196196
var firstError error
197-
if getDebug() {
197+
if IsDebug() {
198198
log.TLogln(fmt.Sprintf("Starting migration of %d %s entries", len(names), xpath))
199199
}
200200
for i, name := range names {
201201
sourceData := source.Get(xpath, name)
202202
if sourceData == nil {
203203
skippedCount++
204-
if getDebug() {
204+
if IsDebug() {
205205
log.TLogln(fmt.Sprintf("[%d/%d] Skipping %s/%s (no data in source)",
206206
i+1, len(names), xpath, name))
207207
}
@@ -213,7 +213,7 @@ func MigrateAll(source, target TorrServerDB, xpath string) (int, int, error) {
213213
// Check if already identical
214214
if equal, err := isByteArraysEqualJson(sourceData, targetData); err == nil && equal {
215215
skippedCount++
216-
if getDebug() {
216+
if IsDebug() {
217217
log.TLogln(fmt.Sprintf("[%d/%d] Skipping %s/%s (already identical)",
218218
i+1, len(names), xpath, name))
219219
}
@@ -233,7 +233,7 @@ func MigrateAll(source, target TorrServerDB, xpath string) (int, int, error) {
233233
}
234234
} else {
235235
migratedCount++
236-
if getDebug() {
236+
if IsDebug() {
237237
log.TLogln(fmt.Sprintf("[%d/%d] Successfully migrated %s/%s",
238238
i+1, len(names), xpath, name))
239239
}
@@ -245,7 +245,7 @@ func MigrateAll(source, target TorrServerDB, xpath string) (int, int, error) {
245245
if firstError != nil {
246246
summary += fmt.Sprintf(", 1+ errors (first: %v)", firstError)
247247
}
248-
if getDebug() {
248+
if IsDebug() {
249249
log.TLogln(summary)
250250
}
251251

@@ -348,7 +348,7 @@ func verifyMigration(source, target TorrServerDB, xpath, name string, originalDa
348348
} else if !equal {
349349
return fmt.Errorf("data mismatch after migration for %s/%s", xpath, name)
350350
}
351-
if getDebug() {
351+
if IsDebug() {
352352
log.TLogln(fmt.Sprintf("Verified migration of %s/%s", xpath, name))
353353
}
354354
return nil

server/settings/settings.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// Add a global lock for database operations during migration
1515
var dbMigrationLock sync.RWMutex
1616

17-
func getDebug() bool {
17+
func IsDebug() bool {
1818
if BTsets != nil {
1919
return BTsets.EnableDebug
2020
}
@@ -89,7 +89,7 @@ func InitSets(readOnly, searchWA bool) {
8989
func determineStoragePreferences(bboltDB, jsonDB TorrServerDB) (settingsInJson, viewedInJson bool) {
9090
// Try to load existing settings first
9191
if existing := loadExistingSettings(bboltDB, jsonDB); existing != nil {
92-
if getDebug() {
92+
if IsDebug() {
9393
log.TLogln(fmt.Sprintf("Found settings: StoreSettingsInJson=%v, StoreViewedInJson=%v",
9494
existing.StoreSettingsInJson, existing.StoreViewedInJson))
9595
}
@@ -110,7 +110,7 @@ func determineStoragePreferences(bboltDB, jsonDB TorrServerDB) (settingsInJson,
110110
viewedInJson = (env == "json")
111111
}
112112

113-
if getDebug() {
113+
if IsDebug() {
114114
log.TLogln(fmt.Sprintf("Using flags: settingsInJson=%v, viewedInJson=%v",
115115
settingsInJson, viewedInJson))
116116
}
@@ -187,7 +187,7 @@ func applyCleanMigrations(bboltDB, jsonDB TorrServerDB, settingsInJson, viewedIn
187187
}
188188

189189
func safeMigrate(source, target TorrServerDB, xpath, name, targetName string, clearSource bool) {
190-
if getDebug() {
190+
if IsDebug() {
191191
log.TLogln(fmt.Sprintf("Checking migration of %s/%s to %s", xpath, name, targetName))
192192
}
193193

@@ -202,7 +202,7 @@ func safeMigrate(source, target TorrServerDB, xpath, name, targetName string, cl
202202
// Clear source if requested
203203
if clearSource {
204204
source.Rem(xpath, name)
205-
if getDebug() {
205+
if IsDebug() {
206206
log.TLogln(fmt.Sprintf("Cleared %s/%s from source", xpath, name))
207207
}
208208
}
@@ -213,7 +213,7 @@ func safeMigrate(source, target TorrServerDB, xpath, name, targetName string, cl
213213
}
214214

215215
func safeMigrateAll(source, target TorrServerDB, xpath, targetName string, clearSource bool) {
216-
if getDebug() {
216+
if IsDebug() {
217217
log.TLogln(fmt.Sprintf("Starting migration of all %s entries to %s", xpath, targetName))
218218
}
219219

@@ -229,7 +229,7 @@ func safeMigrateAll(source, target TorrServerDB, xpath, targetName string, clear
229229
// (accounting for possible duplicates)
230230
if migrated >= sourceCount {
231231
source.Clear(xpath)
232-
if getDebug() {
232+
if IsDebug() {
233233
log.TLogln(fmt.Sprintf("Cleared all %s entries from source", xpath))
234234
}
235235
} else {
@@ -394,7 +394,7 @@ func GetStoragePreferences() map[string]interface{} {
394394
}
395395
}
396396

397-
if getDebug() {
397+
if IsDebug() {
398398
log.TLogln(fmt.Sprintf("GetStoragePreferences: settings=%s, viewed=%s",
399399
prefs["settings"], prefs["viewed"]))
400400
}
@@ -411,14 +411,14 @@ func SetStoragePreferences(prefs map[string]interface{}) error {
411411
return errors.New("cannot change storage preferences. Read-only mode")
412412
}
413413

414-
if getDebug() {
414+
if IsDebug() {
415415
log.TLogln(fmt.Sprintf("SetStoragePreferences received: %v", prefs))
416416
}
417417

418418
// Apply changes
419419
if settingsPref, ok := prefs["settings"].(string); ok && settingsPref != "" {
420420
useJson := (settingsPref == "json")
421-
if getDebug() {
421+
if IsDebug() {
422422
log.TLogln(fmt.Sprintf("Changing settings storage to useJson=%v (was %v)",
423423
useJson, BTsets.StoreSettingsInJson))
424424
}
@@ -431,7 +431,7 @@ func SetStoragePreferences(prefs map[string]interface{}) error {
431431

432432
if viewedPref, ok := prefs["viewed"].(string); ok && viewedPref != "" {
433433
useJson := (viewedPref == "json")
434-
if getDebug() {
434+
if IsDebug() {
435435
log.TLogln(fmt.Sprintf("Changing viewed storage to useJson=%v (was %v)",
436436
useJson, BTsets.StoreViewedInJson))
437437
}

0 commit comments

Comments
 (0)