fix(subsonic): random albums not reshuffling.

See: https://github.com/navidrome/navidrome/issues/3277#issuecomment-2364269787
This commit is contained in:
Deluan 2024-09-20 16:59:46 -04:00
parent 5b89bf747f
commit ecf934feab
5 changed files with 54 additions and 26 deletions

View file

@ -167,20 +167,15 @@ func (r sqlRepository) seedKey() string {
return r.tableName + userId(r.ctx)
}
func (r sqlRepository) seededRandomSort() string {
return fmt.Sprintf("SEEDEDRAND('%s', %s.id)", r.seedKey(), r.tableName)
}
func (r sqlRepository) resetSeededRandom(options []model.QueryOptions) {
if len(options) == 0 || !strings.HasPrefix(options[0].Sort, "SEEDEDRAND(") {
if len(options) == 0 || options[0].Sort != "random" {
return
}
options[0].Sort = fmt.Sprintf("SEEDEDRAND('%s', %s.id)", r.seedKey(), r.tableName)
if options[0].Seed != "" {
hasher.SetSeed(r.seedKey(), options[0].Seed)
return
}
if options[0].Offset == 0 {
hasher.Reseed(r.seedKey())
}