This commit is contained in:
ponzischeme89
2026-08-19 14:25:44 +12:00
parent 2b43b9ef12
commit 590e069366
83 changed files with 8948 additions and 1266 deletions
+22 -2
View File
@@ -94,6 +94,15 @@ type Engine struct {
Library LibrarySource
Tracearr TracearrSource
Behavior BehaviorSource
// TracearrAllowed is the operator's global switch for the Tracearr integration, read
// at call time rather than at construction: a switch consulted once at start-up is
// not a switch, and turning an integration off must stop the calls without a restart.
//
// It is a function rather than a bool for the same reason it is not a policy lookup
// inside the engine: what "switched off" means belongs to the gateway's integrations
// area, and the ranker's business is ranking. Nil means allowed, so every test and
// every caller that predates the switch behaves as it did.
TracearrAllowed func(ctx context.Context) bool
// MinRowItems is the shortest row worth showing. A two-item "Recommended" strip
// looks broken next to full rows, so short rows are dropped entirely.
@@ -144,7 +153,7 @@ func (e *Engine) BuildForYou(
var sessions []tracearr.Session
contextAffinity := NewContextAffinityProfile()
if e.Tracearr != nil {
if e.tracearrUsable(ctx) {
if fetched, traceErr := e.Tracearr.History(ctx, username, 300); traceErr != nil {
e.log.Warn("tracearr history unavailable; using emby signals", "error", traceErr)
} else {
@@ -217,6 +226,17 @@ func powDecay(base float64, position int) float64 {
return math.Pow(base, float64(position))
}
// tracearrUsable reports whether the engine may call Tracearr right now. Falling back to
// Emby's own signals is what happens when it may not, which is the same degradation an
// unreachable Tracearr already produces — so switching it off costs the extra signal and
// never the row.
func (e *Engine) tracearrUsable(ctx context.Context) bool {
if e.Tracearr == nil {
return false
}
return e.TracearrAllowed == nil || e.TracearrAllowed(ctx)
}
func (e *Engine) applyTracearrSignals(
profile *Profile,
history []Item,
@@ -614,7 +634,7 @@ func (e *Engine) BuildRowsForUser(
profile := BuildProfile(history, favorites)
contextAffinity := NewContextAffinityProfile()
if e.Tracearr != nil && strings.TrimSpace(username) != "" {
if e.tracearrUsable(ctx) && strings.TrimSpace(username) != "" {
if sessions, traceErr := e.Tracearr.History(ctx, username, 300); traceErr != nil {
e.log.Warn("tracearr signals unavailable for shelves", "error", traceErr)
} else {