extracted an item refresh service
This commit is contained in:
parent
e8696f54d0
commit
3b2b9c59b2
74
MediaBrowser.Api/ItemRefreshService.cs
Normal file
74
MediaBrowser.Api/ItemRefreshService.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using ServiceStack.ServiceHost;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api
|
||||
{
|
||||
[Route("/Items/{Id}/Refresh", "POST")]
|
||||
[Api(Description = "Refreshes metadata for an item")]
|
||||
public class RefreshItem : IReturnVoid
|
||||
{
|
||||
[ApiMember(Name = "Forced", Description = "Indicates if a normal or forced refresh should occur.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
|
||||
public bool Forced { get; set; }
|
||||
|
||||
[ApiMember(Name = "Recursive", Description = "Indicates if the refresh should occur recursively.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
|
||||
public bool Recursive { get; set; }
|
||||
|
||||
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class ItemRefreshService : BaseApiService
|
||||
{
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
public ItemRefreshService(ILibraryManager libraryManager, IUserManager userManager)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(RefreshItem request)
|
||||
{
|
||||
var task = RefreshItem(request);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes the item.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>Task.</returns>
|
||||
private async Task RefreshItem(RefreshItem request)
|
||||
{
|
||||
var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager);
|
||||
|
||||
var folder = item as Folder;
|
||||
|
||||
try
|
||||
{
|
||||
await item.RefreshMetadata(CancellationToken.None, forceRefresh: request.Forced).ConfigureAwait(false);
|
||||
|
||||
if (folder != null)
|
||||
{
|
||||
await folder.ValidateChildren(new Progress<double>(), CancellationToken.None, request.Recursive,
|
||||
request.Forced).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error refreshing library", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using ServiceStack.ServiceHost;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api
|
||||
{
|
||||
|
|
|
@ -97,20 +97,6 @@ namespace MediaBrowser.Api
|
|||
{
|
||||
}
|
||||
|
||||
[Route("/Items/{Id}/Refresh", "POST")]
|
||||
[Api(Description = "Refreshes metadata for an item")]
|
||||
public class RefreshItem : IReturnVoid
|
||||
{
|
||||
[ApiMember(Name = "Forced", Description = "Indicates if a normal or forced refresh should occur.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
|
||||
public bool Forced { get; set; }
|
||||
|
||||
[ApiMember(Name = "Recursive", Description = "Indicates if the refresh should occur recursively.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
|
||||
public bool Recursive { get; set; }
|
||||
|
||||
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Items/{Id}", "DELETE")]
|
||||
[Api(Description = "Deletes an item from the library and file system")]
|
||||
public class DeleteItem : IReturnVoid
|
||||
|
@ -390,42 +376,5 @@ namespace MediaBrowser.Api
|
|||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(RefreshItem request)
|
||||
{
|
||||
var task = RefreshItem(request);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes the item.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>Task.</returns>
|
||||
private async Task RefreshItem(RefreshItem request)
|
||||
{
|
||||
var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager);
|
||||
|
||||
var folder = item as Folder;
|
||||
|
||||
try
|
||||
{
|
||||
await item.RefreshMetadata(CancellationToken.None, forceRefresh: request.Forced).ConfigureAwait(false);
|
||||
|
||||
if (folder != null)
|
||||
{
|
||||
await folder.ValidateChildren(new Progress<double>(), CancellationToken.None, request.Recursive,
|
||||
request.Forced).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error refreshing library", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
<Compile Include="Images\ImageRequest.cs" />
|
||||
<Compile Include="Images\ImageService.cs" />
|
||||
<Compile Include="Images\ImageWriter.cs" />
|
||||
<Compile Include="ItemRefreshService.cs" />
|
||||
<Compile Include="ItemUpdateService.cs" />
|
||||
<Compile Include="LibraryService.cs" />
|
||||
<Compile Include="Library\LibraryHelpers.cs" />
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
|||
{
|
||||
var handler = new WebRequestHandler
|
||||
{
|
||||
CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache),
|
||||
CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate),
|
||||
AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
|
||||
};
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace MediaBrowser.Controller.Entities.Audio
|
|||
/// <summary>
|
||||
/// Class Artist
|
||||
/// </summary>
|
||||
public class Artist : BaseItem
|
||||
public class Artist : BaseItem, IItemByName
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the user data key.
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace MediaBrowser.Controller.Entities.Audio
|
|||
/// <summary>
|
||||
/// Class MusicGenre
|
||||
/// </summary>
|
||||
public class MusicGenre : BaseItem
|
||||
public class MusicGenre : BaseItem, IItemByName
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the user data key.
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// <summary>
|
||||
/// Class Genre
|
||||
/// </summary>
|
||||
public class Genre : BaseItem
|
||||
public class Genre : BaseItem, IItemByName
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the user data key.
|
||||
|
|
10
MediaBrowser.Controller/Entities/IItemByName.cs
Normal file
10
MediaBrowser.Controller/Entities/IItemByName.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Marker interface
|
||||
/// </summary>
|
||||
public interface IItemByName
|
||||
{
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// <summary>
|
||||
/// This is the full Person object that can be retrieved with all of it's data.
|
||||
/// </summary>
|
||||
public class Person : BaseItem
|
||||
public class Person : BaseItem, IItemByName
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the user data key.
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// <summary>
|
||||
/// Class Studio
|
||||
/// </summary>
|
||||
public class Studio : BaseItem
|
||||
public class Studio : BaseItem, IItemByName
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the user data key.
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// <summary>
|
||||
/// Class Year
|
||||
/// </summary>
|
||||
public class Year : BaseItem
|
||||
public class Year : BaseItem, IItemByName
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the user data key.
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
<Compile Include="Entities\Audio\MusicGenre.cs" />
|
||||
<Compile Include="Entities\Game.cs" />
|
||||
<Compile Include="Entities\IByReferenceItem.cs" />
|
||||
<Compile Include="Entities\IItemByName.cs" />
|
||||
<Compile Include="Entities\MusicVideo.cs" />
|
||||
<Compile Include="Library\ILibraryPostScanTask.cs" />
|
||||
<Compile Include="Library\ILibraryPrescanTask.cs" />
|
||||
|
|
|
@ -392,7 +392,10 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// <param name="item">The item.</param>
|
||||
private void UpdateItemInLibraryCache(BaseItem item)
|
||||
{
|
||||
LibraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; });
|
||||
if (!(item is IItemByName))
|
||||
{
|
||||
LibraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user