refresh people on demand, when needed
This commit is contained in:
parent
325a3cc844
commit
1adcfaadef
|
@ -12,6 +12,8 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommonIO;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
|
||||
namespace MediaBrowser.Api.UserLibrary
|
||||
{
|
||||
|
@ -262,14 +264,16 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IDtoService _dtoService;
|
||||
private readonly IUserViewManager _userViewManager;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, IUserViewManager userViewManager)
|
||||
public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, IUserViewManager userViewManager, IFileSystem fileSystem)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_libraryManager = libraryManager;
|
||||
_userDataRepository = userDataRepository;
|
||||
_dtoService = dtoService;
|
||||
_userViewManager = userViewManager;
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -426,12 +430,14 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetItem request)
|
||||
public async Task<object> Get(GetItem request)
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
|
||||
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : _libraryManager.GetItemById(request.Id);
|
||||
|
||||
await RefreshItemOnDemandIfNeeded(item).ConfigureAwait(false);
|
||||
|
||||
var dtoOptions = GetDtoOptions(request);
|
||||
|
||||
var result = _dtoService.GetBaseItemDto(item, dtoOptions, user);
|
||||
|
@ -439,6 +445,35 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
return ToOptimizedSerializedResultUsingCache(result);
|
||||
}
|
||||
|
||||
private async Task RefreshItemOnDemandIfNeeded(BaseItem item)
|
||||
{
|
||||
if (item is Person)
|
||||
{
|
||||
var hasMetdata = !string.IsNullOrWhiteSpace(item.Overview) && item.HasImage(ImageType.Primary);
|
||||
var performFullRefresh = !hasMetdata && (DateTime.UtcNow - item.DateLastRefreshed).TotalDays >= 7;
|
||||
|
||||
if (!hasMetdata)
|
||||
{
|
||||
var defaultMetadataRefreshMode = performFullRefresh
|
||||
? MetadataRefreshMode.FullRefresh
|
||||
: MetadataRefreshMode.Default;
|
||||
|
||||
var imageRefreshMode = performFullRefresh
|
||||
? ImageRefreshMode.FullRefresh
|
||||
: ImageRefreshMode.Default;
|
||||
|
||||
var options = new MetadataRefreshOptions(_fileSystem)
|
||||
{
|
||||
MetadataRefreshMode = defaultMetadataRefreshMode,
|
||||
ImageRefreshMode = imageRefreshMode,
|
||||
ForceSave = performFullRefresh
|
||||
};
|
||||
|
||||
await item.RefreshMetadata(options, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified request.
|
||||
/// </summary>
|
||||
|
|
|
@ -2213,6 +2213,15 @@ namespace MediaBrowser.Controller.Entities
|
|||
}
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public virtual bool StopRefreshIfLocalMetadataFound
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual IEnumerable<Guid> GetIdsForAncestorQuery()
|
||||
{
|
||||
return new[] { Id };
|
||||
|
|
|
@ -58,6 +58,6 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
string GetPresentationUniqueKey();
|
||||
string CreatePresentationUniqueKey();
|
||||
|
||||
bool StopRefreshIfLocalMetadataFound { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,5 +179,15 @@ namespace MediaBrowser.Controller.Entities.Movies
|
|||
|
||||
return list;
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public override bool StopRefreshIfLocalMetadataFound
|
||||
{
|
||||
get
|
||||
{
|
||||
// Need people id's from internet metadata
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -519,5 +519,15 @@ namespace MediaBrowser.Controller.Entities.TV
|
|||
|
||||
return list;
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public override bool StopRefreshIfLocalMetadataFound
|
||||
{
|
||||
get
|
||||
{
|
||||
// Need people id's from internet metadata
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,5 +124,15 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
return list;
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public override bool StopRefreshIfLocalMetadataFound
|
||||
{
|
||||
get
|
||||
{
|
||||
// Need people id's from internet metadata
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -532,7 +532,7 @@ namespace MediaBrowser.Providers.Manager
|
|||
}
|
||||
|
||||
// Local metadata is king - if any is found don't run remote providers
|
||||
if (!options.ReplaceAllMetadata && (!hasLocalMetadata || options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh))
|
||||
if (!options.ReplaceAllMetadata && (!hasLocalMetadata || options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh || !item.StopRefreshIfLocalMetadataFound))
|
||||
{
|
||||
var remoteResult = await ExecuteRemoteProviders(temp, logName, id, providers.OfType<IRemoteMetadataProvider<TItemType, TIdType>>(), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
|
Loading…
Reference in New Issue
Block a user