mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-04 12:36:37 +08:00
Optimize home/library loading and SQLite query performance
- Replace home preview N+1 queries with a single window-function batch query - Cache library previews and series card lists (15s TTL, shared with media cache) - Tune SQLite: larger page cache, mmap, wal_autocheckpoint, ANALYZE on migrate - Defer history fetch on library page until last_played sort is selected - Yield to browser between paginated library loads to keep UI responsive Co-authored-by: truewhile <truewhile@users.noreply.github.com>
This commit is contained in:
@@ -24,11 +24,19 @@ func AutoMigrate(db *gorm.DB) error {
|
||||
return err
|
||||
}
|
||||
if isSQLite(db) {
|
||||
return ensureMediaSearchIndex(db)
|
||||
if err := ensureMediaSearchIndex(db); err != nil {
|
||||
return err
|
||||
}
|
||||
return ensureSQLiteQueryOptimizer(db)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ensureSQLiteQueryOptimizer(db *gorm.DB) error {
|
||||
// Refresh planner statistics so indexes on large media tables are used.
|
||||
return db.Exec("ANALYZE").Error
|
||||
}
|
||||
|
||||
func ensurePostgresColumnCompatibility(db *gorm.DB) error {
|
||||
if !isPostgres(db) {
|
||||
return nil
|
||||
|
||||
@@ -114,7 +114,10 @@ func buildSQLiteDSN(cfg *config.Config) string {
|
||||
if cfg.Database.CacheSize != 0 {
|
||||
dsn += fmt.Sprintf("&_pragma=cache_size(%d)", cfg.Database.CacheSize)
|
||||
}
|
||||
dsn += "&_pragma=temp_store(MEMORY)&_pragma=mmap_size(268435456)"
|
||||
dsn += "&_pragma=temp_store(MEMORY)&_pragma=mmap_size(536870912)"
|
||||
if cfg.Database.WALMode {
|
||||
dsn += "&_pragma=wal_autocheckpoint(1000)"
|
||||
}
|
||||
return dsn
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user