add refresh item api method

This commit is contained in:
Luke Pulverenti 2013-05-22 00:21:36 -04:00
parent b310c98656
commit 95afe143e8
2 changed files with 26 additions and 45 deletions

View File

@ -96,6 +96,17 @@ namespace MediaBrowser.Api
{ {
} }
[Route("/Items/{Id}/Refresh", "POST")]
[Api(Description = "Refreshes metadata for an item")]
public class RefreshItem : IReturnVoid
{
[ApiMember(Name = "IsForced", Description = "Indicates if a normal or forced refresh should occur.", IsRequired = true, DataType = "bool", ParameterType = "query", Verb = "POST")]
public bool IsForced { get; set; }
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Id { get; set; }
}
[Route("/Items/Counts", "GET")] [Route("/Items/Counts", "GET")]
[Api(Description = "Gets counts of various item types")] [Api(Description = "Gets counts of various item types")]
public class GetItemCounts : IReturn<ItemCounts> public class GetItemCounts : IReturn<ItemCounts>
@ -304,6 +315,17 @@ namespace MediaBrowser.Api
return ToOptimizedResult(result); return ToOptimizedResult(result);
} }
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
public void Post(RefreshItem request)
{
var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager);
item.RefreshMetadata(CancellationToken.None, forceRefresh: request.IsForced);
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>

View File

@ -1,5 +1,4 @@
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
@ -97,11 +96,6 @@ namespace MediaBrowser.Server.Implementations.Providers
MetadataProviders = providers.OrderBy(e => e.Priority).ToArray(); MetadataProviders = providers.OrderBy(e => e.Priority).ToArray();
} }
/// <summary>
/// The _supported providers key
/// </summary>
private readonly Guid _supportedProvidersKey = "SupportedProviders".GetMD5();
/// <summary> /// <summary>
/// Runs all metadata providers for an entity, and returns true or false indicating if at least one was refreshed and requires persistence /// Runs all metadata providers for an entity, and returns true or false indicating if at least one was refreshed and requires persistence
/// </summary> /// </summary>
@ -120,40 +114,10 @@ namespace MediaBrowser.Server.Implementations.Providers
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
// Determine if supported providers have changed
var supportedProviders = MetadataProviders.Where(p => p.Supports(item)).ToList();
BaseProviderInfo supportedProvidersInfo;
var supportedProvidersValue = string.Join(string.Empty, supportedProviders.Select(i => i.GetType().Name));
var providersChanged = false;
item.ProviderData.TryGetValue(_supportedProvidersKey, out supportedProvidersInfo);
var supportedProvidersHash = supportedProvidersValue.GetMD5();
if (supportedProvidersInfo != null)
{
// Force refresh if the supported providers have changed
providersChanged = force = force || supportedProvidersHash != supportedProvidersInfo.Data;
// If providers have changed, clear provider info and update the supported providers hash
if (providersChanged)
{
_logger.Debug("Providers changed for {0}. Clearing and forcing refresh.", item.Name);
item.ProviderData.Clear();
}
}
if (providersChanged)
{
supportedProvidersInfo.Data = supportedProvidersHash;
}
if (force) item.ClearMetaValues(); if (force) item.ClearMetaValues();
// Run the normal providers sequentially in order of priority // Run the normal providers sequentially in order of priority
foreach (var provider in supportedProviders) foreach (var provider in MetadataProviders.Where(p => p.Supports(item)))
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -206,12 +170,7 @@ namespace MediaBrowser.Server.Implementations.Providers
result |= results.Contains(true); result |= results.Contains(true);
} }
if (providersChanged) return result;
{
item.ProviderData[_supportedProvidersKey] = supportedProvidersInfo;
}
return result || providersChanged;
} }
/// <summary> /// <summary>