mirror of
https://github.com/navidrome/navidrome.git
synced 2025-07-14 07:31:28 +03:00
* Fix artist not being marked as touched during quick scans When a new album is added during quick scans, artists were not being marked as 'touched' due to media files having older modification times than the scan completion time. Changes: - Add 'updated_at' to artist Put() columns in scanner to ensure timestamp is set when artists are processed - Simplify RefreshStats query to check artist.updated_at directly instead of complex media file joins - Artists from new albums now properly get refreshed in later phases This fixes the issue where newly added albums would have incomplete artist information after quick scans. * fix(missing): refresh artist stats in background after deleting missing files Signed-off-by: Deluan <deluan@navidrome.org> * fix(request): add InternalAuth to user context Signed-off-by: Deluan <deluan@navidrome.org> * Add comprehensive test for artist stats update during quick scans - Add test that verifies artist statistics are correctly updated when new files are added during incremental scans - Test ensures both overall stats (AlbumCount, SongCount) and role-specific stats are properly refreshed - Validates fix for artist stats not being refreshed during quick scans when new albums are added - Uses real artist repository instead of mock to verify actual stats calculation behavior --------- Signed-off-by: Deluan <deluan@navidrome.org>
128 lines
3.1 KiB
Go
128 lines
3.1 KiB
Go
package request
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
)
|
|
|
|
type contextKey string
|
|
|
|
const (
|
|
User = contextKey("user")
|
|
Username = contextKey("username")
|
|
Client = contextKey("client")
|
|
Version = contextKey("version")
|
|
Player = contextKey("player")
|
|
Transcoding = contextKey("transcoding")
|
|
ClientUniqueId = contextKey("clientUniqueId")
|
|
ReverseProxyIp = contextKey("reverseProxyIp")
|
|
InternalAuth = contextKey("internalAuth") // Used for internal API calls, e.g., from the plugins
|
|
)
|
|
|
|
var allKeys = []contextKey{
|
|
User,
|
|
Username,
|
|
Client,
|
|
Version,
|
|
Player,
|
|
Transcoding,
|
|
ClientUniqueId,
|
|
ReverseProxyIp,
|
|
InternalAuth,
|
|
}
|
|
|
|
func WithUser(ctx context.Context, u model.User) context.Context {
|
|
return context.WithValue(ctx, User, u)
|
|
}
|
|
|
|
func WithUsername(ctx context.Context, username string) context.Context {
|
|
return context.WithValue(ctx, Username, username)
|
|
}
|
|
|
|
func WithClient(ctx context.Context, client string) context.Context {
|
|
return context.WithValue(ctx, Client, client)
|
|
}
|
|
|
|
func WithVersion(ctx context.Context, version string) context.Context {
|
|
return context.WithValue(ctx, Version, version)
|
|
}
|
|
|
|
func WithPlayer(ctx context.Context, player model.Player) context.Context {
|
|
return context.WithValue(ctx, Player, player)
|
|
}
|
|
|
|
func WithTranscoding(ctx context.Context, t model.Transcoding) context.Context {
|
|
return context.WithValue(ctx, Transcoding, t)
|
|
}
|
|
|
|
func WithClientUniqueId(ctx context.Context, clientUniqueId string) context.Context {
|
|
return context.WithValue(ctx, ClientUniqueId, clientUniqueId)
|
|
}
|
|
|
|
func WithReverseProxyIp(ctx context.Context, reverseProxyIp string) context.Context {
|
|
return context.WithValue(ctx, ReverseProxyIp, reverseProxyIp)
|
|
}
|
|
|
|
func WithInternalAuth(ctx context.Context, username string) context.Context {
|
|
return context.WithValue(ctx, InternalAuth, username)
|
|
}
|
|
|
|
func UserFrom(ctx context.Context) (model.User, bool) {
|
|
v, ok := ctx.Value(User).(model.User)
|
|
return v, ok
|
|
}
|
|
|
|
func UsernameFrom(ctx context.Context) (string, bool) {
|
|
v, ok := ctx.Value(Username).(string)
|
|
return v, ok
|
|
}
|
|
|
|
func ClientFrom(ctx context.Context) (string, bool) {
|
|
v, ok := ctx.Value(Client).(string)
|
|
return v, ok
|
|
}
|
|
|
|
func VersionFrom(ctx context.Context) (string, bool) {
|
|
v, ok := ctx.Value(Version).(string)
|
|
return v, ok
|
|
}
|
|
|
|
func PlayerFrom(ctx context.Context) (model.Player, bool) {
|
|
v, ok := ctx.Value(Player).(model.Player)
|
|
return v, ok
|
|
}
|
|
|
|
func TranscodingFrom(ctx context.Context) (model.Transcoding, bool) {
|
|
v, ok := ctx.Value(Transcoding).(model.Transcoding)
|
|
return v, ok
|
|
}
|
|
|
|
func ClientUniqueIdFrom(ctx context.Context) (string, bool) {
|
|
v, ok := ctx.Value(ClientUniqueId).(string)
|
|
return v, ok
|
|
}
|
|
|
|
func ReverseProxyIpFrom(ctx context.Context) (string, bool) {
|
|
v, ok := ctx.Value(ReverseProxyIp).(string)
|
|
return v, ok
|
|
}
|
|
|
|
func InternalAuthFrom(ctx context.Context) (string, bool) {
|
|
if v := ctx.Value(InternalAuth); v != nil {
|
|
if username, ok := v.(string); ok {
|
|
return username, true
|
|
}
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
func AddValues(ctx, requestCtx context.Context) context.Context {
|
|
for _, key := range allKeys {
|
|
if v := requestCtx.Value(key); v != nil {
|
|
ctx = context.WithValue(ctx, key, v)
|
|
}
|
|
}
|
|
return ctx
|
|
}
|