From a67c8df25244844b03e745645f3abcc343a59697 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 16 Nov 2015 18:32:32 -0500 Subject: [PATCH 1/9] update ffmpeg --- .../FFMpeg/FFMpegDownloadInfo.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs index b4d2e5b851..0314fcc7eb 100644 --- a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs +++ b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs @@ -54,7 +54,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg info.FFMpegFilename = "ffmpeg.exe"; info.FFProbeFilename = "ffprobe.exe"; - info.Version = "20150918"; + info.Version = "20151111"; info.ArchiveType = "7z"; switch (environment.SystemArchitecture) @@ -83,14 +83,14 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg case Architecture.X86_X64: return new[] { - "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20150918-win64.7z", - "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20150916-git-cbbd906-win64-static.7z" + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20151111-win64.7z", + "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20151109-git-480bad7-win64-static.7z" }; case Architecture.X86: return new[] { - "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20150918-win32.7z", - "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20150916-git-cbbd906-win32-static.7z" + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20151111-win32.7z", + "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20151109-git-480bad7-win32-static.7z" }; } break; From 5013fddc2db5262c2297dce01fb89383ef5dcb27 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 17 Nov 2015 13:23:18 -0500 Subject: [PATCH 2/9] update channel manager --- .../Channels/ChannelManager.cs | 77 +++++++++++-------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index ba759dcb9a..26fd1a01d2 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -104,6 +104,11 @@ namespace MediaBrowser.Server.Implementations.Channels .OrderBy(i => i.Name); } + public IEnumerable GetInstalledChannelIds() + { + return GetAllChannels().Select(i => GetInternalChannelId(i.Name)); + } + public Task> GetChannelsInternal(ChannelQuery query, CancellationToken cancellationToken) { var user = string.IsNullOrWhiteSpace(query.UserId) @@ -408,25 +413,15 @@ namespace MediaBrowser.Server.Implementations.Channels private async Task GetChannel(IChannel channelInfo, CancellationToken cancellationToken) { + var parentFolder = await GetInternalChannelFolder(cancellationToken).ConfigureAwait(false); + var parentFolderId = parentFolder.Id; + var id = GetInternalChannelId(channelInfo.Name); var path = Channel.GetInternalMetadataPath(_config.ApplicationPaths.InternalMetadataPath, id); var isNew = false; - - if (!_fileSystem.DirectoryExists(path)) - { - _logger.Debug("Creating directory {0}", path); - - _fileSystem.CreateDirectory(path); - - if (!_fileSystem.DirectoryExists(path)) - { - throw new IOException("Path not created: " + path); - } - - isNew = true; - } + var forceUpdate = false; var item = _libraryManager.GetItemById(id) as Channel; var channelId = channelInfo.Name.GetMD5().ToString("N"); @@ -438,18 +433,29 @@ namespace MediaBrowser.Server.Implementations.Channels Name = channelInfo.Name, Id = id, DateCreated = _fileSystem.GetCreationTimeUtc(path), - DateModified = _fileSystem.GetLastWriteTimeUtc(path), - Path = path, - ChannelId = channelId + DateModified = _fileSystem.GetLastWriteTimeUtc(path) }; isNew = true; } - if (!string.Equals(item.ChannelId, channelId, StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(item.Path, path, StringComparison.OrdinalIgnoreCase)) { isNew = true; } + item.Path = path; + + if (!string.Equals(item.ChannelId, channelId, StringComparison.OrdinalIgnoreCase)) + { + forceUpdate = true; + } + item.ChannelId = channelId; + + if (item.ParentId != parentFolderId) + { + forceUpdate = true; + } + item.ParentId = parentFolderId; item.OfficialRating = GetOfficialRating(channelInfo.ParentalRating); item.Overview = channelInfo.Description; @@ -459,13 +465,17 @@ namespace MediaBrowser.Server.Implementations.Channels { item.Name = channelInfo.Name; } - - await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem) + + if (isNew) { - ForceSave = isNew - - }, cancellationToken); + await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); + } + else if (forceUpdate) + { + await item.UpdateToRepository(ItemUpdateType.None, cancellationToken).ConfigureAwait(false); + } + await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem), cancellationToken); return item; } @@ -1225,6 +1235,7 @@ namespace MediaBrowser.Server.Implementations.Channels { BaseItem item; bool isNew; + bool forceUpdate = false; if (info.Type == ChannelItemType.Folder) { @@ -1254,7 +1265,6 @@ namespace MediaBrowser.Server.Implementations.Channels item.ProductionYear = info.ProductionYear; item.ProviderIds = info.ProviderIds; item.OfficialRating = info.OfficialRating; - item.DateCreated = info.DateCreated ?? DateTime.UtcNow; } @@ -1262,17 +1272,18 @@ namespace MediaBrowser.Server.Implementations.Channels channelItem.ChannelId = internalChannelId.ToString("N"); + if (item.ParentId != internalChannelId) + { + forceUpdate = true; + } + item.ParentId = internalChannelId; + if (!string.Equals(channelItem.ExternalId, info.Id, StringComparison.OrdinalIgnoreCase)) { - isNew = true; + forceUpdate = true; } channelItem.ExternalId = info.Id; - if (isNew) - { - channelItem.Tags = info.Tags; - } - var channelMediaItem = item as IChannelMediaItem; if (channelMediaItem != null) @@ -1286,7 +1297,7 @@ namespace MediaBrowser.Server.Implementations.Channels item.Path = mediaSource == null ? null : mediaSource.Path; } - if (!string.IsNullOrWhiteSpace(info.ImageUrl)) + if (!string.IsNullOrWhiteSpace(info.ImageUrl) && !item.HasImage(ImageType.Primary)) { item.SetImagePath(ImageType.Primary, info.ImageUrl); } @@ -1300,6 +1311,10 @@ namespace MediaBrowser.Server.Implementations.Channels await _libraryManager.UpdatePeople(item, info.People ?? new List()).ConfigureAwait(false); } } + else if (forceUpdate) + { + await item.UpdateToRepository(ItemUpdateType.None, cancellationToken).ConfigureAwait(false); + } return item; } From 2ee91249e54b9346823c52bcea7e2a770b04e5c1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 17 Nov 2015 13:24:40 -0500 Subject: [PATCH 3/9] revert channel manager changes --- .../Channels/ChannelManager.cs | 77 ++++++++----------- 1 file changed, 31 insertions(+), 46 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index 26fd1a01d2..ba759dcb9a 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -104,11 +104,6 @@ namespace MediaBrowser.Server.Implementations.Channels .OrderBy(i => i.Name); } - public IEnumerable GetInstalledChannelIds() - { - return GetAllChannels().Select(i => GetInternalChannelId(i.Name)); - } - public Task> GetChannelsInternal(ChannelQuery query, CancellationToken cancellationToken) { var user = string.IsNullOrWhiteSpace(query.UserId) @@ -413,15 +408,25 @@ namespace MediaBrowser.Server.Implementations.Channels private async Task GetChannel(IChannel channelInfo, CancellationToken cancellationToken) { - var parentFolder = await GetInternalChannelFolder(cancellationToken).ConfigureAwait(false); - var parentFolderId = parentFolder.Id; - var id = GetInternalChannelId(channelInfo.Name); var path = Channel.GetInternalMetadataPath(_config.ApplicationPaths.InternalMetadataPath, id); var isNew = false; - var forceUpdate = false; + + if (!_fileSystem.DirectoryExists(path)) + { + _logger.Debug("Creating directory {0}", path); + + _fileSystem.CreateDirectory(path); + + if (!_fileSystem.DirectoryExists(path)) + { + throw new IOException("Path not created: " + path); + } + + isNew = true; + } var item = _libraryManager.GetItemById(id) as Channel; var channelId = channelInfo.Name.GetMD5().ToString("N"); @@ -433,29 +438,18 @@ namespace MediaBrowser.Server.Implementations.Channels Name = channelInfo.Name, Id = id, DateCreated = _fileSystem.GetCreationTimeUtc(path), - DateModified = _fileSystem.GetLastWriteTimeUtc(path) + DateModified = _fileSystem.GetLastWriteTimeUtc(path), + Path = path, + ChannelId = channelId }; isNew = true; } - if (!string.Equals(item.Path, path, StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(item.ChannelId, channelId, StringComparison.OrdinalIgnoreCase)) { isNew = true; } - item.Path = path; - - if (!string.Equals(item.ChannelId, channelId, StringComparison.OrdinalIgnoreCase)) - { - forceUpdate = true; - } - item.ChannelId = channelId; - - if (item.ParentId != parentFolderId) - { - forceUpdate = true; - } - item.ParentId = parentFolderId; item.OfficialRating = GetOfficialRating(channelInfo.ParentalRating); item.Overview = channelInfo.Description; @@ -465,17 +459,13 @@ namespace MediaBrowser.Server.Implementations.Channels { item.Name = channelInfo.Name; } - - if (isNew) + + await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem) { - await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); - } - else if (forceUpdate) - { - await item.UpdateToRepository(ItemUpdateType.None, cancellationToken).ConfigureAwait(false); - } + ForceSave = isNew + + }, cancellationToken); - await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem), cancellationToken); return item; } @@ -1235,7 +1225,6 @@ namespace MediaBrowser.Server.Implementations.Channels { BaseItem item; bool isNew; - bool forceUpdate = false; if (info.Type == ChannelItemType.Folder) { @@ -1265,6 +1254,7 @@ namespace MediaBrowser.Server.Implementations.Channels item.ProductionYear = info.ProductionYear; item.ProviderIds = info.ProviderIds; item.OfficialRating = info.OfficialRating; + item.DateCreated = info.DateCreated ?? DateTime.UtcNow; } @@ -1272,18 +1262,17 @@ namespace MediaBrowser.Server.Implementations.Channels channelItem.ChannelId = internalChannelId.ToString("N"); - if (item.ParentId != internalChannelId) - { - forceUpdate = true; - } - item.ParentId = internalChannelId; - if (!string.Equals(channelItem.ExternalId, info.Id, StringComparison.OrdinalIgnoreCase)) { - forceUpdate = true; + isNew = true; } channelItem.ExternalId = info.Id; + if (isNew) + { + channelItem.Tags = info.Tags; + } + var channelMediaItem = item as IChannelMediaItem; if (channelMediaItem != null) @@ -1297,7 +1286,7 @@ namespace MediaBrowser.Server.Implementations.Channels item.Path = mediaSource == null ? null : mediaSource.Path; } - if (!string.IsNullOrWhiteSpace(info.ImageUrl) && !item.HasImage(ImageType.Primary)) + if (!string.IsNullOrWhiteSpace(info.ImageUrl)) { item.SetImagePath(ImageType.Primary, info.ImageUrl); } @@ -1311,10 +1300,6 @@ namespace MediaBrowser.Server.Implementations.Channels await _libraryManager.UpdatePeople(item, info.People ?? new List()).ConfigureAwait(false); } } - else if (forceUpdate) - { - await item.UpdateToRepository(ItemUpdateType.None, cancellationToken).ConfigureAwait(false); - } return item; } From 8af05ef4ece4f66ea3659435ccb75aff2f3ee112 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 Nov 2015 15:38:27 -0500 Subject: [PATCH 4/9] update links --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ee0855b74..f10556ee70 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ It features a REST-based api with built-in documention to facilitate client deve ## Emby Apps - [Android Mobile (Play Store)](https://play.google.com/store/apps/details?id=com.mb.android "Android Mobile (Play Store)") -- [Android Mobile (Amazon)](http://www.amazon.com/Emby-for-Android/dp/B00GVH9O0I "Android Mobile (Amazon)") +- [Android Mobile (Amazon)](http://www.amazon.com/Emby-Mobile/dp/B017OSA1QS "Android Mobile (Amazon)") - [Android TV](https://play.google.com/store/apps/details?id=tv.emby.embyatv "Android TV") - [Amazon Fire TV](http://www.amazon.com/Emby-for-Fire-TV/dp/B00VVJKTW8 "Amazon Fire TV") - [HTML5](http://app.emby.media "HTML5") From 2267a1712380e1ada6c866eb5c4d468f7e2e33ed Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 Nov 2015 15:38:50 -0500 Subject: [PATCH 5/9] update schedules direct timeouts --- .../LiveTv/Listings/SchedulesDirect.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs index e041b3a2a6..86815ae41e 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs @@ -126,7 +126,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings Url = ApiUrl + "/programs", UserAgent = UserAgent, CancellationToken = cancellationToken, - LogErrorResponseBody = true + LogErrorResponseBody = true, + // The data can be large so give it some extra time + TimeoutMs = 60000 }; httpOptions.RequestHeaders["token"] = token; @@ -463,7 +465,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings UserAgent = UserAgent, CancellationToken = cancellationToken, RequestContent = imageIdString, - LogErrorResponseBody = true + LogErrorResponseBody = true, + // The data can be large so give it some extra time + TimeoutMs = 60000 }; List images; using (var innerResponse2 = await _httpClient.Post(httpOptions)) From 2f525a0c1c336ed2c8d545fc4d9b8a3986f336cf Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 Nov 2015 15:39:11 -0500 Subject: [PATCH 6/9] update image provider --- .../Manager/ItemImageProvider.cs | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Providers/Manager/ItemImageProvider.cs b/MediaBrowser.Providers/Manager/ItemImageProvider.cs index 838306e133..a4710bec47 100644 --- a/MediaBrowser.Providers/Manager/ItemImageProvider.cs +++ b/MediaBrowser.Providers/Manager/ItemImageProvider.cs @@ -17,6 +17,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.MediaInfo; namespace MediaBrowser.Providers.Manager @@ -505,13 +506,46 @@ namespace MediaBrowser.Providers.Manager return true; } - return false; + if (!item.IsSaveLocalMetadataEnabled()) + { + return true; + } + + if (item is IItemByName && !(item is MusicArtist)) + { + var hasDualAccess = item as IHasDualAccess; + if (hasDualAccess == null || hasDualAccess.IsAccessedByName) + { + return true; + } + } + + switch (type) + { + case ImageType.Primary: + return false; + case ImageType.Thumb: + return false; + case ImageType.Logo: + return false; + case ImageType.Backdrop: + return false; + case ImageType.Screenshot: + return false; + default: + return true; + } } private void SaveImageStub(IHasImages item, ImageType imageType, string url) { var newIndex = item.AllowsMultipleImages(imageType) ? item.GetImages(imageType).Count() : 0; + SaveImageStub(item, imageType, url, newIndex); + } + + private void SaveImageStub(IHasImages item, ImageType imageType, string url, int newIndex) + { item.SetImage(new ItemImageInfo { Path = url, @@ -540,7 +574,7 @@ namespace MediaBrowser.Providers.Manager { SaveImageStub(item, imageType, url); result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate; - return; + continue; } try From 435c1416fc6b97140ad208930384f4e7b9437daa Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 Nov 2015 15:46:00 -0500 Subject: [PATCH 7/9] add hlsjs --- MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 50bad0aa96..8747298219 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -468,6 +468,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest From d6418e6e9c2a0b797aae9f611c10cbc380b5fd16 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 Nov 2015 21:04:50 -0500 Subject: [PATCH 8/9] update hls --- MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 6ca2677e76..4d7a10f02b 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -173,11 +173,14 @@ namespace MediaBrowser.Api.Playback.Hls } await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); + var released = false; try { if (FileSystem.FileExists(segmentPath)) { job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); + ApiEntryPoint.Instance.TranscodingStartLock.Release(); + released = true; return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false); } else @@ -238,7 +241,10 @@ namespace MediaBrowser.Api.Playback.Hls } finally { - ApiEntryPoint.Instance.TranscodingStartLock.Release(); + if (!released) + { + ApiEntryPoint.Instance.TranscodingStartLock.Release(); + } } //Logger.Info("waiting for {0}", segmentPath); From 5d5583b02584e4afe8a2619f8ed3739860418f5f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 Nov 2015 21:04:59 -0500 Subject: [PATCH 9/9] update sync --- .../Sync/TargetDataProvider.cs | 84 ++++++++++++------- 1 file changed, 52 insertions(+), 32 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Sync/TargetDataProvider.cs b/MediaBrowser.Server.Implementations/Sync/TargetDataProvider.cs index 41d56d9596..24c62a58f6 100644 --- a/MediaBrowser.Server.Implementations/Sync/TargetDataProvider.cs +++ b/MediaBrowser.Server.Implementations/Sync/TargetDataProvider.cs @@ -60,46 +60,61 @@ namespace MediaBrowser.Server.Implementations.Sync return _fileSystem.GetValidFilename(filename); } + private async Task> RetrieveItems(CancellationToken cancellationToken) + { + _logger.Debug("Getting {0} from {1}", string.Join(MediaSync.PathSeparatorString, GetRemotePath().ToArray()), _provider.Name); + + var fileResult = await _provider.GetFiles(new FileQuery + { + FullPath = GetRemotePath().ToArray() + + }, _target, cancellationToken).ConfigureAwait(false); + + if (fileResult.Items.Length > 0) + { + using (var stream = await _provider.GetFile(fileResult.Items[0].Id, _target, new Progress(), cancellationToken)) + { + return _json.DeserializeFromStream>(stream); + } + } + + return new List(); + } + private async Task EnsureData(CancellationToken cancellationToken) { if (_items == null) { - _logger.Debug("Getting {0} from {1}", string.Join(MediaSync.PathSeparatorString, GetRemotePath().ToArray()), _provider.Name); - - var fileResult = await _provider.GetFiles(new FileQuery - { - FullPath = GetRemotePath().ToArray() - - }, _target, cancellationToken).ConfigureAwait(false); - - if (fileResult.Items.Length > 0) - { - using (var stream = await _provider.GetFile(fileResult.Items[0].Id, _target, new Progress(), cancellationToken)) - { - _items = _json.DeserializeFromStream>(stream); - } - } - else - { - _items = new List(); - } + _items = await RetrieveItems(cancellationToken).ConfigureAwait(false); } } - private async Task SaveData(CancellationToken cancellationToken) + private async Task SaveData(List items, CancellationToken cancellationToken) { using (var stream = new MemoryStream()) { - _json.SerializeToStream(_items, stream); + _json.SerializeToStream(items, stream); // Save to sync provider stream.Position = 0; - await _provider.SendFile(stream, GetRemotePath(), _target, new Progress(), cancellationToken).ConfigureAwait(false); + var remotePath = GetRemotePath(); + _logger.Debug("Saving data.json to {0}. Remote path: {1}", _provider.Name, string.Join("/", remotePath)); + + await _provider.SendFile(stream, remotePath, _target, new Progress(), cancellationToken).ConfigureAwait(false); } } - private async Task GetData(Func, T> dataFactory) + private async Task GetData(bool enableCache, Func, T> dataFactory) { + if (!enableCache) + { + var items = await RetrieveItems(CancellationToken.None).ConfigureAwait(false); + var newCache = items.ToList(); + var result = dataFactory(items); + await UpdateCache(newCache).ConfigureAwait(false); + return result; + } + await _dataLock.WaitAsync().ConfigureAwait(false); try @@ -115,16 +130,21 @@ namespace MediaBrowser.Server.Implementations.Sync } private async Task UpdateData(Func, List> action) + { + var items = await RetrieveItems(CancellationToken.None).ConfigureAwait(false); + items = action(items); + await SaveData(items.ToList(), CancellationToken.None).ConfigureAwait(false); + + await UpdateCache(null).ConfigureAwait(false); + } + + private async Task UpdateCache(List list) { await _dataLock.WaitAsync().ConfigureAwait(false); try { - await EnsureData(CancellationToken.None).ConfigureAwait(false); - - _items = action(_items); - - await SaveData(CancellationToken.None).ConfigureAwait(false); + _items = list; } finally { @@ -134,7 +154,7 @@ namespace MediaBrowser.Server.Implementations.Sync public Task> GetLocalItems(SyncTarget target, string serverId) { - return GetData(items => items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase)).ToList()); + return GetData(false, items => items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase)).ToList()); } public Task AddOrUpdate(SyncTarget target, LocalItem item) @@ -157,17 +177,17 @@ namespace MediaBrowser.Server.Implementations.Sync public Task Get(SyncTarget target, string id) { - return GetData(items => items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase))); + return GetData(true, items => items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase))); } public Task> GetItems(SyncTarget target, string serverId, string itemId) { - return GetData(items => items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase) && string.Equals(i.ItemId, itemId, StringComparison.OrdinalIgnoreCase)).ToList()); + return GetData(true, items => items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase) && string.Equals(i.ItemId, itemId, StringComparison.OrdinalIgnoreCase)).ToList()); } public Task> GetItemsBySyncJobItemId(SyncTarget target, string serverId, string syncJobItemId) { - return GetData(items => items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase) && string.Equals(i.SyncJobItemId, syncJobItemId, StringComparison.OrdinalIgnoreCase)).ToList()); + return GetData(false, items => items.Where(i => string.Equals(i.ServerId, serverId, StringComparison.OrdinalIgnoreCase) && string.Equals(i.SyncJobItemId, syncJobItemId, StringComparison.OrdinalIgnoreCase)).ToList()); } } }