mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 04:27:37 +03:00
fix(server): only build core.Agents once
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
a04167672c
commit
0372339e1b
4 changed files with 15 additions and 8 deletions
|
@ -65,7 +65,7 @@ func CreateSubsonicAPIRouter(ctx context.Context) *subsonic.Router {
|
||||||
dataStore := persistence.New(sqlDB)
|
dataStore := persistence.New(sqlDB)
|
||||||
fileCache := artwork.GetImageCache()
|
fileCache := artwork.GetImageCache()
|
||||||
fFmpeg := ffmpeg.New()
|
fFmpeg := ffmpeg.New()
|
||||||
agentsAgents := agents.New(dataStore)
|
agentsAgents := agents.GetAgents(dataStore)
|
||||||
externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents)
|
externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents)
|
||||||
artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata)
|
artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata)
|
||||||
transcodingCache := core.GetTranscodingCache()
|
transcodingCache := core.GetTranscodingCache()
|
||||||
|
@ -89,7 +89,7 @@ func CreatePublicRouter() *public.Router {
|
||||||
dataStore := persistence.New(sqlDB)
|
dataStore := persistence.New(sqlDB)
|
||||||
fileCache := artwork.GetImageCache()
|
fileCache := artwork.GetImageCache()
|
||||||
fFmpeg := ffmpeg.New()
|
fFmpeg := ffmpeg.New()
|
||||||
agentsAgents := agents.New(dataStore)
|
agentsAgents := agents.GetAgents(dataStore)
|
||||||
externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents)
|
externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents)
|
||||||
artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata)
|
artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata)
|
||||||
transcodingCache := core.GetTranscodingCache()
|
transcodingCache := core.GetTranscodingCache()
|
||||||
|
@ -133,7 +133,7 @@ func CreateScanner(ctx context.Context) scanner.Scanner {
|
||||||
dataStore := persistence.New(sqlDB)
|
dataStore := persistence.New(sqlDB)
|
||||||
fileCache := artwork.GetImageCache()
|
fileCache := artwork.GetImageCache()
|
||||||
fFmpeg := ffmpeg.New()
|
fFmpeg := ffmpeg.New()
|
||||||
agentsAgents := agents.New(dataStore)
|
agentsAgents := agents.GetAgents(dataStore)
|
||||||
externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents)
|
externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents)
|
||||||
artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata)
|
artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata)
|
||||||
cacheWarmer := artwork.NewCacheWarmer(artworkArtwork, fileCache)
|
cacheWarmer := artwork.NewCacheWarmer(artworkArtwork, fileCache)
|
||||||
|
@ -149,7 +149,7 @@ func CreateScanWatcher(ctx context.Context) scanner.Watcher {
|
||||||
dataStore := persistence.New(sqlDB)
|
dataStore := persistence.New(sqlDB)
|
||||||
fileCache := artwork.GetImageCache()
|
fileCache := artwork.GetImageCache()
|
||||||
fFmpeg := ffmpeg.New()
|
fFmpeg := ffmpeg.New()
|
||||||
agentsAgents := agents.New(dataStore)
|
agentsAgents := agents.GetAgents(dataStore)
|
||||||
externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents)
|
externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents)
|
||||||
artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata)
|
artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata)
|
||||||
cacheWarmer := artwork.NewCacheWarmer(artworkArtwork, fileCache)
|
cacheWarmer := artwork.NewCacheWarmer(artworkArtwork, fileCache)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
"github.com/navidrome/navidrome/utils"
|
"github.com/navidrome/navidrome/utils"
|
||||||
|
"github.com/navidrome/navidrome/utils/singleton"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Agents struct {
|
type Agents struct {
|
||||||
|
@ -17,7 +18,13 @@ type Agents struct {
|
||||||
agents []Interface
|
agents []Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ds model.DataStore) *Agents {
|
func GetAgents(ds model.DataStore) *Agents {
|
||||||
|
return singleton.GetInstance(func() *Agents {
|
||||||
|
return createAgents(ds)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func createAgents(ds model.DataStore) *Agents {
|
||||||
var order []string
|
var order []string
|
||||||
if conf.Server.Agents != "" {
|
if conf.Server.Agents != "" {
|
||||||
order = strings.Split(conf.Server.Agents, ",")
|
order = strings.Split(conf.Server.Agents, ",")
|
||||||
|
|
|
@ -29,7 +29,7 @@ var _ = Describe("Agents", func() {
|
||||||
var ag *Agents
|
var ag *Agents
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
conf.Server.Agents = ""
|
conf.Server.Agents = ""
|
||||||
ag = New(ds)
|
ag = createAgents(ds)
|
||||||
})
|
})
|
||||||
|
|
||||||
It("calls the placeholder GetArtistImages", func() {
|
It("calls the placeholder GetArtistImages", func() {
|
||||||
|
@ -49,7 +49,7 @@ var _ = Describe("Agents", func() {
|
||||||
Register("disabled", func(model.DataStore) Interface { return nil })
|
Register("disabled", func(model.DataStore) Interface { return nil })
|
||||||
Register("empty", func(model.DataStore) Interface { return &emptyAgent{} })
|
Register("empty", func(model.DataStore) Interface { return &emptyAgent{} })
|
||||||
conf.Server.Agents = "empty,fake,disabled"
|
conf.Server.Agents = "empty,fake,disabled"
|
||||||
ag = New(ds)
|
ag = createAgents(ds)
|
||||||
Expect(ag.AgentName()).To(Equal("agents"))
|
Expect(ag.AgentName()).To(Equal("agents"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ var Set = wire.NewSet(
|
||||||
NewPlayers,
|
NewPlayers,
|
||||||
NewShare,
|
NewShare,
|
||||||
NewPlaylists,
|
NewPlaylists,
|
||||||
agents.New,
|
agents.GetAgents,
|
||||||
ffmpeg.New,
|
ffmpeg.New,
|
||||||
scrobbler.GetPlayTracker,
|
scrobbler.GetPlayTracker,
|
||||||
playback.GetInstance,
|
playback.GetInstance,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue