update library setup

This commit is contained in:
Luke Pulverenti 2015-10-16 00:46:41 -04:00
parent 2c5ee7e2cf
commit a8e5aba643
8 changed files with 123 additions and 24 deletions

View File

@ -283,8 +283,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
var url = options.Url;
var urlHash = url.ToLower().GetMD5().ToString("N");
var semaphore = GetLock(url);
var responseCachePath = Path.Combine(_appPaths.CachePath, "httpclient", urlHash);
response = await GetCachedResponse(responseCachePath, options.CacheLength, url).ConfigureAwait(false);
@ -293,6 +292,8 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
return response;
}
var semaphore = GetLock(url);
await semaphore.WaitAsync(options.CancellationToken).ConfigureAwait(false);
try

View File

@ -13,6 +13,7 @@ namespace MediaBrowser.Controller.Entities
{
public string ViewType { get; set; }
public Guid ParentId { get; set; }
public Guid DisplayParentId { get; set; }
public Guid? UserId { get; set; }
@ -28,7 +29,11 @@ namespace MediaBrowser.Controller.Entities
{
var parent = this as Folder;
if (ParentId != Guid.Empty)
if (DisplayParentId != Guid.Empty)
{
parent = LibraryManager.GetItemById(DisplayParentId) as Folder ?? parent;
}
else if (ParentId != Guid.Empty)
{
parent = LibraryManager.GetItemById(ParentId) as Folder ?? parent;
}

View File

@ -385,6 +385,21 @@ namespace MediaBrowser.Controller.Library
string uniqueId,
CancellationToken cancellationToken);
/// <summary>
/// Gets the shadow view.
/// </summary>
/// <param name="parent">The parent.</param>
/// <param name="viewType">Type of the view.</param>
/// <param name="sortName">Name of the sort.</param>
/// <param name="uniqueId">The unique identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task&lt;UserView&gt;.</returns>
Task<UserView> GetShadowView(BaseItem parent,
string viewType,
string sortName,
string uniqueId,
CancellationToken cancellationToken);
/// <summary>
/// Determines whether [is video file] [the specified path].
/// </summary>

View File

@ -216,10 +216,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
_logger.Debug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
await _ffProbeResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
using (var processWrapper = new ProcessWrapper(process, this, _logger))
{
await _ffProbeResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
StartProcess(processWrapper);
@ -536,10 +536,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
_logger.Debug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
await resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
using (var processWrapper = new ProcessWrapper(process, this, _logger))
{
await resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
bool ranToCompletion;
var memoryStream = new MemoryStream();

View File

@ -353,14 +353,27 @@ namespace MediaBrowser.Providers.Movies
return mainResult;
}
private static long _lastRequestTicks;
/// <summary>
/// Gets the movie db response.
/// </summary>
internal Task<Stream> GetMovieDbResponse(HttpRequestOptions options)
internal async Task<Stream> GetMovieDbResponse(HttpRequestOptions options)
{
options.ResourcePool = MovieDbResourcePool;
var requestIntervalMs = 250;
var delayTicks = (requestIntervalMs * 10000) - (DateTime.UtcNow.Ticks - _lastRequestTicks);
var delayMs = Math.Min(delayTicks / 10000, requestIntervalMs);
return _httpClient.Get(options);
if (delayMs > 0)
{
_logger.Debug("Throttling Tmdb by {0} ms", delayMs);
await Task.Delay(Convert.ToInt32(delayMs)).ConfigureAwait(false);
}
options.ResourcePool = MovieDbResourcePool;
_lastRequestTicks = DateTime.UtcNow.Ticks;
return await _httpClient.Get(options).ConfigureAwait(false);
}
public TheMovieDbOptions GetTheMovieDbOptions()

View File

@ -300,7 +300,7 @@ namespace MediaBrowser.Providers.Music
if (!isSearch)
{
options.CacheMode = CacheMode.Unconditional;
options.CacheLength = TimeSpan.FromDays(7);
options.CacheLength = TimeSpan.FromDays(3);
}
using (var xml = await _httpClient.Get(options).ConfigureAwait(false))

View File

@ -1792,7 +1792,7 @@ namespace MediaBrowser.Server.Implementations.Library
if (!string.IsNullOrWhiteSpace(parentId))
{
item.ParentId = new Guid(parentId);
item.DisplayParentId = new Guid(parentId);
}
await CreateItem(item, cancellationToken).ConfigureAwait(false);
@ -1826,6 +1826,75 @@ namespace MediaBrowser.Server.Implementations.Library
return item;
}
public async Task<UserView> GetShadowView(BaseItem parent,
string viewType,
string sortName,
string uniqueId,
CancellationToken cancellationToken)
{
if (parent == null)
{
throw new ArgumentNullException("parent");
}
var name = parent.Name;
var parentId = parent.Id;
var idValues = "37_namedview_" + name + parentId + (viewType ?? string.Empty);
if (!string.IsNullOrWhiteSpace(uniqueId))
{
idValues += uniqueId;
}
var id = GetNewItemId(idValues, typeof(UserView));
var path = parent.Path;
var item = GetItemById(id) as UserView;
var isNew = false;
if (item == null)
{
_fileSystem.CreateDirectory(path);
item = new UserView
{
Path = path,
Id = id,
DateCreated = DateTime.UtcNow,
Name = name,
ViewType = viewType,
ForcedSortName = sortName
};
item.DisplayParentId = parentId;
await CreateItem(item, cancellationToken).ConfigureAwait(false);
isNew = true;
}
if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase))
{
item.ViewType = viewType;
await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
}
var refresh = isNew || (DateTime.UtcNow - item.DateLastRefreshed) >= _viewRefreshInterval;
if (refresh)
{
_providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem)
{
// Need to force save to increment DateLastSaved
ForceSave = true
});
}
return item;
}
public async Task<UserView> GetNamedView(string name,
string parentId,
string viewType,
@ -1868,7 +1937,7 @@ namespace MediaBrowser.Server.Implementations.Library
if (!string.IsNullOrWhiteSpace(parentId))
{
item.ParentId = new Guid(parentId);
item.DisplayParentId = new Guid(parentId);
}
await CreateItem(item, cancellationToken).ConfigureAwait(false);

View File

@ -74,11 +74,11 @@ namespace MediaBrowser.Server.Implementations.Library
}
else if (plainFolderIds.Contains(folder.Id))
{
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, false, string.Empty, cancellationToken).ConfigureAwait(false));
list.Add(await GetUserView(folder, folderViewType, false, string.Empty, cancellationToken).ConfigureAwait(false));
}
else if (!string.IsNullOrWhiteSpace(folderViewType))
{
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, cancellationToken).ConfigureAwait(false));
list.Add(await GetUserView(folder, folderViewType, true, string.Empty, cancellationToken).ConfigureAwait(false));
}
else
{
@ -209,23 +209,18 @@ namespace MediaBrowser.Server.Implementations.Library
public async Task<UserView> GetUserView(List<ICollectionFolder> parents, List<Folder> currentViews, string viewType, string sortName, User user, CancellationToken cancellationToken)
{
var name = _localizationManager.GetLocalizedString("ViewType" + viewType);
var enableUserViews = _config.Configuration.EnableUserViews;
if (parents.Count == 1 && parents.All(i => string.Equals((enableUserViews ? i.GetViewType(user) : i.CollectionType), viewType, StringComparison.OrdinalIgnoreCase)))
{
if (!string.IsNullOrWhiteSpace(parents[0].Name))
{
name = parents[0].Name;
}
var parentId = parents[0].Id;
var enableRichView = !user.Configuration.PlainFolderViews.Contains(parentId.ToString("N"), StringComparer.OrdinalIgnoreCase);
return await GetUserView(parentId, name, viewType, enableRichView, string.Empty, cancellationToken).ConfigureAwait(false);
return await GetUserView((Folder)parents[0], viewType, enableRichView, string.Empty, cancellationToken).ConfigureAwait(false);
}
var name = _localizationManager.GetLocalizedString("ViewType" + viewType);
return await _libraryManager.GetNamedView(user, name, viewType, sortName, cancellationToken).ConfigureAwait(false);
}
@ -235,10 +230,11 @@ namespace MediaBrowser.Server.Implementations.Library
return _libraryManager.GetNamedView(user, name, parentId.ToString("N"), viewType, sortName, null, cancellationToken);
}
public Task<UserView> GetUserView(Guid parentId, string name, string viewType, bool enableRichView, string sortName, CancellationToken cancellationToken)
public Task<UserView> GetUserView(Folder parent, string viewType, bool enableRichView, string sortName, CancellationToken cancellationToken)
{
viewType = enableRichView ? viewType : null;
return _libraryManager.GetNamedView(name, parentId.ToString("N"), viewType, sortName, null, cancellationToken);
return _libraryManager.GetShadowView(parent, viewType, sortName, null, cancellationToken);
}
public List<Tuple<BaseItem, List<BaseItem>>> GetLatestItems(LatestItemsQuery request)