1
0
mirror of synced 2024-11-23 22:41:01 +01:00

Try change to a custom distinct logic for recent songs

This commit is contained in:
asesidaa 2022-09-08 18:28:46 +08:00
parent 5e662f8cdb
commit eff5ac478f

View File

@ -46,13 +46,24 @@ public class UserDataController : BaseController<UserDataController>
var recentSongs = context.SongPlayData
.Where(datum => datum.Baid == request.Baid)
.AsEnumerable()
.DistinctBy(datum => datum.SongId)
.OrderByDescending(datum => datum.PlayTime)
.ThenByDescending(datum => datum.SongNumber)
.Select(datum => datum.SongId)
.Take(10)
.ToArray();
// Use custom implementation as distictby cannot guarantee preserved element
var recentSet = new SortedSet<uint>();
foreach (var id in recentSongs)
{
recentSet.Add(id);
if (recentSet.Count == 10)
{
break;
}
}
recentSongs = recentSet.ToArray();
var userData = new UserDatum();
if (context.UserData.Any(datum => datum.Baid == request.Baid))
{