update user queries

This commit is contained in:
Luke Pulverenti
2016-05-09 00:56:41 -04:00
parent 99084edabe
commit f80c1d93c0
8 changed files with 82 additions and 35 deletions

View File

@@ -116,7 +116,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
premiereDate,
options,
overwriteExisting,
false,
false,
result,
cancellationToken).ConfigureAwait(false);
}
@@ -202,7 +202,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
null,
options,
true,
request.RememberCorrection,
request.RememberCorrection,
result,
cancellationToken).ConfigureAwait(false);
@@ -219,7 +219,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
DateTime? premiereDate,
AutoOrganizeOptions options,
bool overwriteExisting,
bool rememberCorrection,
bool rememberCorrection,
FileOrganizationResult result,
CancellationToken cancellationToken)
{
@@ -242,7 +242,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
premiereDate,
options,
overwriteExisting,
rememberCorrection,
rememberCorrection,
result,
cancellationToken);
}
@@ -255,7 +255,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
DateTime? premiereDate,
AutoOrganizeOptions options,
bool overwriteExisting,
bool rememberCorrection,
bool rememberCorrection,
FileOrganizationResult result,
CancellationToken cancellationToken)
{
@@ -536,7 +536,11 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
result.ExtractedName = nameWithoutYear;
result.ExtractedYear = yearInName;
var series = _libraryManager.RootFolder.GetRecursiveChildren(i => i is Series)
var series = _libraryManager.GetItemList(new Controller.Entities.InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(Series).Name },
Recursive = true
})
.Cast<Series>()
.Select(i => NameUtils.GetMatchScore(nameWithoutYear, yearInName, i))
.Where(i => i.Item2 > 0)
@@ -550,10 +554,12 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
if (info != null)
{
series = _libraryManager.RootFolder
.GetRecursiveChildren(i => i is Series)
.Cast<Series>()
.FirstOrDefault(i => string.Equals(i.Name, info.ItemName, StringComparison.OrdinalIgnoreCase));
series = _libraryManager.GetItemList(new Controller.Entities.InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(Series).Name },
Recursive = true
}).Cast<Series>()
.FirstOrDefault(i => string.Equals(i.Name, info.ItemName, StringComparison.OrdinalIgnoreCase));
}
}

View File

@@ -22,7 +22,7 @@ namespace MediaBrowser.Server.Implementations.Library
{
public event EventHandler<UserDataSaveEventArgs> UserDataSaved;
private readonly ConcurrentDictionary<string, UserItemData> _userData = new ConcurrentDictionary<string, UserItemData>();
private readonly Dictionary<string, UserItemData> _userData = new Dictionary<string, UserItemData>(StringComparer.OrdinalIgnoreCase);
private readonly ILogger _logger;
private readonly IServerConfigurationManager _config;
@@ -66,8 +66,10 @@ namespace MediaBrowser.Server.Implementations.Library
var newValue = userData;
// Once it succeeds, put it into the dictionary to make it available to everyone else
_userData.AddOrUpdate(GetCacheKey(userId, key), newValue, delegate { return newValue; });
lock (_userData)
{
_userData[GetCacheKey(userId, key)] = newValue;
}
}
catch (Exception ex)
{
@@ -154,13 +156,33 @@ namespace MediaBrowser.Server.Implementations.Library
throw new ArgumentNullException("key");
}
return _userData.GetOrAdd(GetCacheKey(userId, key), keyName => GetUserDataFromRepository(userId, key));
lock (_userData)
{
var cacheKey = GetCacheKey(userId, key);
UserItemData value;
if (_userData.TryGetValue(cacheKey, out value))
{
return value;
}
value = GetUserDataFromRepository(userId, key);
_userData[cacheKey] = value;
return value;
}
}
private UserItemData GetUserDataFromRepository(Guid userId, string key)
{
var data = Repository.GetUserData(userId, key);
if (data == null)
{
data = new UserItemData
{
UserId = userId,
Key = key
};
}
return data;
}

View File

@@ -2056,6 +2056,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
var whereClauses = new List<string>();
if (EnableJoinUserData(query))
{
whereClauses.Add("UserId=@UserId");
}
if (query.IsCurrentSchema.HasValue)
{
if (query.IsCurrentSchema.Value)

View File

@@ -296,11 +296,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
}
return new UserItemData
{
UserId = userId,
Key = key
};
return null;
}
}

View File

@@ -12,6 +12,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
@@ -85,8 +86,13 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
/// <returns>Task.</returns>
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
var videos = _libraryManager.RootFolder.GetRecursiveChildren(i => i is Video)
.Cast<Video>()
var videos = _libraryManager.GetItemList(new InternalItemsQuery
{
MediaTypes = new[] { MediaType.Video },
IsFolder = false,
Recursive = true
})
.OfType<Video>()
.ToList();
var numComplete = 0;
@@ -97,7 +103,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
try
{
previouslyFailedImages = _fileSystem.ReadAllText(failHistoryPath)
previouslyFailedImages = _fileSystem.ReadAllText(failHistoryPath)
.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
}