a7919b9bac
The user data cache and the item's in-memory rows were both filled once per replica and never invalidated, so a pod serving a playback tick read its own stale resume position and wrote it back over the position another pod had just saved, silently losing resume points, played state, favourites and ratings. - drop the user item data cache - read single and batched user data from the database on every query - prefetch user data for in-memory sorts and filters so each stays one query - cover the lost update against real PostgreSQL with two manager instances
29 lines
950 B
C#
29 lines
950 B
C#
#nullable disable
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
namespace MediaBrowser.Controller.Sorting
|
|
{
|
|
/// <summary>
|
|
/// Helpers shared by the comparers that sort on user data.
|
|
/// </summary>
|
|
public static class UserBaseItemComparerExtensions
|
|
{
|
|
/// <summary>
|
|
/// Gets the user data for an item, preferring the batch the sort prefetched.
|
|
/// </summary>
|
|
/// <param name="comparer">The comparer.</param>
|
|
/// <param name="item">The item.</param>
|
|
/// <returns>The item's user data.</returns>
|
|
public static UserItemData GetUserData(this IUserBaseItemComparer comparer, BaseItem item)
|
|
{
|
|
if (comparer.PrefetchedUserData is not null && comparer.PrefetchedUserData.TryGetValue(item.Id, out var userData))
|
|
{
|
|
return userData;
|
|
}
|
|
|
|
return comparer.UserDataManager.GetUserData(comparer.User, item);
|
|
}
|
|
}
|
|
}
|