mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
refactor(scanner): unexport artistSplitExceptionsRx
All external callers go through WithParticipantExceptions, so the accessor does not need to be part of the model package API.
This commit is contained in:
parent
3b41bab94c
commit
8bb1deb7b1
@ -137,12 +137,12 @@ type artistSplitExceptionsCache struct {
|
||||
|
||||
var artistSplitExceptions atomic.Pointer[artistSplitExceptionsCache]
|
||||
|
||||
// ArtistSplitExceptionsRx returns the regex for Scanner.ArtistSplitExceptions,
|
||||
// artistSplitExceptionsRx returns the regex for Scanner.ArtistSplitExceptions,
|
||||
// or nil if none are configured. Compiled lazily (config hooks only run once
|
||||
// per process, before tests can override the option) and cached until the
|
||||
// configured list changes. Lock-free on the cache-hit path, as this is called
|
||||
// per tag mapping per scanned file, across concurrent scanner goroutines.
|
||||
func ArtistSplitExceptionsRx() *regexp.Regexp {
|
||||
func artistSplitExceptionsRx() *regexp.Regexp {
|
||||
names := conf.Server.Scanner.ArtistSplitExceptions
|
||||
if c := artistSplitExceptions.Load(); c != nil && slices.Equal(c.names, names) {
|
||||
return c.rx
|
||||
@ -174,7 +174,7 @@ var participantTagNames = sync.OnceValue(func() map[TagName]struct{} {
|
||||
// exceptions attached when name is a participant (artist/role) tag.
|
||||
func (c TagConf) WithParticipantExceptions(name TagName) TagConf {
|
||||
if _, ok := participantTagNames()[name]; ok {
|
||||
c.ExceptionsRx = ArtistSplitExceptionsRx()
|
||||
c.ExceptionsRx = artistSplitExceptionsRx()
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
@ -144,30 +144,30 @@ var _ = Describe("TagConf", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Describe("ArtistSplitExceptionsRx", func() {
|
||||
Describe("artistSplitExceptionsRx", func() {
|
||||
BeforeEach(func() {
|
||||
DeferCleanup(configtest.SetupConfig())
|
||||
})
|
||||
|
||||
It("returns nil when no exceptions are configured", func() {
|
||||
conf.Server.Scanner.ArtistSplitExceptions = nil
|
||||
Expect(ArtistSplitExceptionsRx()).To(BeNil())
|
||||
Expect(artistSplitExceptionsRx()).To(BeNil())
|
||||
})
|
||||
|
||||
It("compiles the configured exceptions", func() {
|
||||
conf.Server.Scanner.ArtistSplitExceptions = []string{"Iron and Wine"}
|
||||
rx := ArtistSplitExceptionsRx()
|
||||
rx := artistSplitExceptionsRx()
|
||||
Expect(rx).ToNot(BeNil())
|
||||
Expect(rx.MatchString("iron and wine")).To(BeTrue())
|
||||
})
|
||||
|
||||
It("caches the compiled regex until the configuration changes", func() {
|
||||
conf.Server.Scanner.ArtistSplitExceptions = []string{"Iron and Wine"}
|
||||
first := ArtistSplitExceptionsRx()
|
||||
Expect(ArtistSplitExceptionsRx()).To(BeIdenticalTo(first))
|
||||
first := artistSplitExceptionsRx()
|
||||
Expect(artistSplitExceptionsRx()).To(BeIdenticalTo(first))
|
||||
|
||||
conf.Server.Scanner.ArtistSplitExceptions = []string{"AC/DC"}
|
||||
second := ArtistSplitExceptionsRx()
|
||||
second := artistSplitExceptionsRx()
|
||||
Expect(second).ToNot(BeIdenticalTo(first))
|
||||
Expect(second.MatchString("AC/DC")).To(BeTrue())
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user