mirror of
https://github.com/navidrome/navidrome.git
synced 2026-04-03 06:41:01 +00:00
Compare commits
3 Commits
cecd0500fe
...
0f79572d52
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f79572d52 | ||
|
|
ca83ebbb53 | ||
|
|
50c9195820 |
@ -131,6 +131,7 @@ type configOptions struct {
|
||||
DevEnablePluginsInsights bool
|
||||
DevPluginCompilationTimeout time.Duration
|
||||
DevExternalArtistFetchMultiplier float64
|
||||
DevOptimizeDB bool
|
||||
}
|
||||
|
||||
type scannerOptions struct {
|
||||
@ -427,7 +428,7 @@ func validatePurgeMissingOption() error {
|
||||
}
|
||||
}
|
||||
if !valid {
|
||||
err := fmt.Errorf("Invalid Scanner.PurgeMissing value: '%s'. Must be one of: %v", Server.Scanner.PurgeMissing, allowedValues)
|
||||
err := fmt.Errorf("invalid Scanner.PurgeMissing value: '%s'. Must be one of: %v", Server.Scanner.PurgeMissing, allowedValues)
|
||||
log.Error(err.Error())
|
||||
Server.Scanner.PurgeMissing = consts.PurgeMissingNever
|
||||
return err
|
||||
@ -609,6 +610,7 @@ func setViperDefaults() {
|
||||
viper.SetDefault("devenablepluginsinsights", true)
|
||||
viper.SetDefault("devplugincompilationtimeout", time.Minute)
|
||||
viper.SetDefault("devexternalartistfetchmultiplier", 1.5)
|
||||
viper.SetDefault("devoptimizedb", true)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
15
db/db.go
15
db/db.go
@ -45,10 +45,12 @@ func Db() *sql.DB {
|
||||
if err != nil {
|
||||
log.Fatal("Error opening database", err)
|
||||
}
|
||||
_, err = db.Exec("PRAGMA optimize=0x10002")
|
||||
if err != nil {
|
||||
log.Error("Error applying PRAGMA optimize", err)
|
||||
return nil
|
||||
if conf.Server.DevOptimizeDB {
|
||||
_, err = db.Exec("PRAGMA optimize=0x10002")
|
||||
if err != nil {
|
||||
log.Error("Error applying PRAGMA optimize", err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return db
|
||||
})
|
||||
@ -99,7 +101,7 @@ func Init(ctx context.Context) func() {
|
||||
log.Fatal(ctx, "Failed to apply new migrations", err)
|
||||
}
|
||||
|
||||
if hasSchemaChanges {
|
||||
if hasSchemaChanges && conf.Server.DevOptimizeDB {
|
||||
log.Debug(ctx, "Applying PRAGMA optimize after schema changes")
|
||||
_, err = db.ExecContext(ctx, "PRAGMA optimize")
|
||||
if err != nil {
|
||||
@ -114,6 +116,9 @@ func Init(ctx context.Context) func() {
|
||||
|
||||
// Optimize runs PRAGMA optimize on each connection in the pool
|
||||
func Optimize(ctx context.Context) {
|
||||
if !conf.Server.DevOptimizeDB {
|
||||
return
|
||||
}
|
||||
numConns := Db().Stats().OpenConnections
|
||||
if numConns == 0 {
|
||||
log.Debug(ctx, "No open connections to optimize")
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
"github.com/navidrome/navidrome/consts"
|
||||
)
|
||||
|
||||
@ -21,11 +22,13 @@ func notice(tx *sql.Tx, msg string) {
|
||||
// Call this in migrations that requires a full rescan
|
||||
func forceFullRescan(tx *sql.Tx) error {
|
||||
// If a full scan is required, most probably the query optimizer is outdated, so we run `analyze`.
|
||||
_, err := tx.Exec(`ANALYZE;`)
|
||||
if err != nil {
|
||||
return err
|
||||
if conf.Server.DevOptimizeDB {
|
||||
_, err := tx.Exec(`ANALYZE;`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = tx.Exec(fmt.Sprintf(`
|
||||
_, err := tx.Exec(fmt.Sprintf(`
|
||||
INSERT OR REPLACE into property (id, value) values ('%s', '1');
|
||||
`, consts.FullScanAfterMigrationFlagKey))
|
||||
return err
|
||||
|
||||
@ -179,7 +179,9 @@ func (r *libraryRepository) ScanEnd(id int) error {
|
||||
// https://www.sqlite.org/pragma.html#pragma_optimize
|
||||
// Use mask 0x10000 to check table sizes without running ANALYZE
|
||||
// Running ANALYZE can cause query planner issues with expression-based collation indexes
|
||||
_, err = r.executeSQL(Expr("PRAGMA optimize=0x10000;"))
|
||||
if conf.Server.DevOptimizeDB {
|
||||
_, err = r.executeSQL(Expr("PRAGMA optimize=0x10000;"))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@ -300,6 +300,8 @@
|
||||
},
|
||||
"actions": {
|
||||
"scan": "Сканировать библиотеку",
|
||||
"quickScan": "Быстрое сканирование",
|
||||
"fullScan": "Полное сканирование",
|
||||
"manageUsers": "Управление доступом пользователей",
|
||||
"viewDetails": "Просмотреть подробности"
|
||||
},
|
||||
@ -308,6 +310,9 @@
|
||||
"updated": "Библиотека успешно обновлена",
|
||||
"deleted": "Библиотека успешно удалена",
|
||||
"scanStarted": "Сканирование библиотеки начато",
|
||||
"quickScanStarted": "Быстрое сканирование началось",
|
||||
"fullScanStarted": "Началось полное сканирование",
|
||||
"scanError": "Ошибка при запуске сканирования. Проверьте логи",
|
||||
"scanCompleted": "Сканирование библиотеки закончено"
|
||||
},
|
||||
"validation": {
|
||||
@ -625,4 +630,4 @@
|
||||
"empty": "Ничего не играет",
|
||||
"minutesAgo": "%{smart_count} минут назад |||| %{smart_count} минут назад"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user