badger/internal/library/library.go

37 lines
1.1 KiB
Go
Raw Normal View History

2023-03-14 09:53:33 +01:00
package library
import (
"sync"
"velvettear/badger/internal/config"
"velvettear/badger/internal/database"
"velvettear/badger/internal/log"
"velvettear/badger/internal/tools"
)
// exported function(s)
func Update() {
timestamp := tools.LogTimestamp()
log.Info("database update started...")
// find and filter for unknown / changed files
files, deletedTrackIDs := filterChangedFiles(findFiles(config.LibraryDirectory()))
// if no changed files are detected and no files were deleted exit
if len(files) == 0 && !removeDeletedTracks(deletedTrackIDs) {
log.InfoTimed("database update finished, no changes were detected", timestamp)
return
}
if len(files) > 0 {
// setup waitgroup and communication channel
ipc := make(chan wrapper)
wait := new(sync.WaitGroup)
wait.Add(2)
// parse the files and store the generated metadata asynchronously
go parseFiles(files, ipc, wait)
go storeMetadata(ipc, wait)
wait.Wait()
close(ipc)
}
// persist the in memory database to the filesystem
database.Persist()
log.InfoTimed("database update finished", timestamp)
}