mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-22 10:04:44 +01:00
moved displaypreferences to usermanager to solve concurrency issues
This commit is contained in:
@@ -74,109 +74,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The _display prefs
|
||||
/// </summary>
|
||||
private IEnumerable<DisplayPreferences> _displayPreferences;
|
||||
/// <summary>
|
||||
/// The _display prefs initialized
|
||||
/// </summary>
|
||||
private bool _displayPreferencesInitialized;
|
||||
/// <summary>
|
||||
/// The _display prefs sync lock
|
||||
/// </summary>
|
||||
private object _displayPreferencesSyncLock = new object();
|
||||
/// <summary>
|
||||
/// Gets the display prefs.
|
||||
/// </summary>
|
||||
/// <value>The display prefs.</value>
|
||||
[IgnoreDataMember]
|
||||
public IEnumerable<DisplayPreferences> DisplayPreferences
|
||||
{
|
||||
get
|
||||
{
|
||||
// Call ToList to exhaust the stream because we'll be iterating over this multiple times
|
||||
LazyInitializer.EnsureInitialized(ref _displayPreferences, ref _displayPreferencesInitialized, ref _displayPreferencesSyncLock, () => Kernel.Instance.DisplayPreferencesRepository.RetrieveDisplayPreferences(this).ToList());
|
||||
return _displayPreferences;
|
||||
}
|
||||
private set
|
||||
{
|
||||
_displayPreferences = value;
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
_displayPreferencesInitialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display prefs.
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="createIfNull">if set to <c>true</c> [create if null].</param>
|
||||
/// <returns>DisplayPreferences.</returns>
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
public DisplayPreferences GetDisplayPreferences(User user, bool createIfNull)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
if (DisplayPreferences == null)
|
||||
{
|
||||
if (!createIfNull)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
AddOrUpdateDisplayPreferences(user, new DisplayPreferences { UserId = user.Id });
|
||||
}
|
||||
|
||||
var data = DisplayPreferences.FirstOrDefault(u => u.UserId == user.Id);
|
||||
|
||||
if (data == null && createIfNull)
|
||||
{
|
||||
data = new DisplayPreferences { UserId = user.Id };
|
||||
AddOrUpdateDisplayPreferences(user, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the or update display prefs.
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
public void AddOrUpdateDisplayPreferences(User user, DisplayPreferences data)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
data.UserId = user.Id;
|
||||
|
||||
if (DisplayPreferences == null)
|
||||
{
|
||||
DisplayPreferences = new[] { data };
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = DisplayPreferences.Where(u => u.UserId != user.Id).ToList();
|
||||
list.Add(data);
|
||||
DisplayPreferences = list;
|
||||
}
|
||||
}
|
||||
|
||||
#region Indexing
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -28,11 +28,13 @@ namespace MediaBrowser.Controller.Library
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
public DtoBuilder(ILogger logger, ILibraryManager libraryManager)
|
||||
public DtoBuilder(ILogger logger, ILibraryManager libraryManager, IUserManager userManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_libraryManager = libraryManager;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -141,9 +143,9 @@ namespace MediaBrowser.Controller.Library
|
||||
tasks.Add(AttachPeople(dto, item));
|
||||
}
|
||||
|
||||
AttachBasicFields(dto, item, fields);
|
||||
tasks.Add(AttachUserSpecificInfo(dto, item, user, fields));
|
||||
|
||||
AttachUserSpecificInfo(dto, item, user, fields);
|
||||
AttachBasicFields(dto, item, fields);
|
||||
|
||||
// Make sure all the tasks we kicked off have completed.
|
||||
if (tasks.Count > 0)
|
||||
@@ -161,7 +163,7 @@ namespace MediaBrowser.Controller.Library
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="fields">The fields.</param>
|
||||
private void AttachUserSpecificInfo(BaseItemDto dto, BaseItem item, User user, List<ItemFields> fields)
|
||||
private async Task AttachUserSpecificInfo(BaseItemDto dto, BaseItem item, User user, List<ItemFields> fields)
|
||||
{
|
||||
if (fields.Contains(ItemFields.UserData))
|
||||
{
|
||||
@@ -175,7 +177,9 @@ namespace MediaBrowser.Controller.Library
|
||||
|
||||
if (item.IsFolder && fields.Contains(ItemFields.DisplayPreferences))
|
||||
{
|
||||
dto.DisplayPreferences = ((Folder)item).GetDisplayPreferences(user, false) ?? new DisplayPreferences { UserId = user.Id };
|
||||
var displayPreferencesId = ((Folder) item).DisplayPreferencesId;
|
||||
|
||||
dto.DisplayPreferences = await _userManager.GetDisplayPreferences(user.Id, displayPreferencesId).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (item.IsFolder)
|
||||
@@ -191,7 +195,7 @@ namespace MediaBrowser.Controller.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the primary image aspect ratio.
|
||||
/// </summary>
|
||||
|
||||
@@ -107,15 +107,6 @@ namespace MediaBrowser.Controller.Library
|
||||
/// <returns>Task.</returns>
|
||||
Task ValidateMediaLibrary(IProgress<double> progress, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Saves display preferences for a Folder
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="folder">The folder.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SaveDisplayPreferencesForFolder(User user, Folder folder, DisplayPreferences data);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default view.
|
||||
/// </summary>
|
||||
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Library
|
||||
{
|
||||
@@ -178,5 +179,24 @@ namespace MediaBrowser.Controller.Library
|
||||
/// <param name="newPassword">The new password.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task ChangePassword(User user, string newPassword);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display preferences.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="displayPreferencesId">The display preferences id.</param>
|
||||
/// <returns>DisplayPreferences.</returns>
|
||||
Task<DisplayPreferences> GetDisplayPreferences(Guid userId, Guid displayPreferencesId);
|
||||
|
||||
/// <summary>
|
||||
/// Saves display preferences for an item
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="displayPreferencesId">The display preferences id.</param>
|
||||
/// <param name="displayPreferences">The display preferences.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SaveDisplayPreferences(Guid userId, Guid displayPreferencesId, DisplayPreferences displayPreferences,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Collections.Generic;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -14,16 +13,20 @@ namespace MediaBrowser.Controller.Persistence
|
||||
/// <summary>
|
||||
/// Saves display preferences for an item
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="displayPreferencesId">The display preferences id.</param>
|
||||
/// <param name="displayPreferences">The display preferences.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SaveDisplayPreferences(Folder item, CancellationToken cancellationToken);
|
||||
Task SaveDisplayPreferences(Guid userId, Guid displayPreferencesId, DisplayPreferences displayPreferences,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets display preferences for an item
|
||||
/// Gets the display preferences.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns>IEnumerable{DisplayPreferences}.</returns>
|
||||
IEnumerable<DisplayPreferences> RetrieveDisplayPreferences(Folder item);
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="displayPreferencesId">The display preferences id.</param>
|
||||
/// <returns>Task{DisplayPreferences}.</returns>
|
||||
Task<DisplayPreferences> GetDisplayPreferences(Guid userId, Guid displayPreferencesId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user