From 076a07a54661da993b7ecefd5e294b11b8d90873 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 1 Mar 2016 14:39:46 -0500 Subject: [PATCH 1/4] optimize FindByPath --- .../Playback/Progressive/VideoService.cs | 5 +++++ MediaBrowser.Controller/Entities/BaseItem.cs | 2 +- .../Entities/InternalItemsQuery.cs | 2 ++ .../Library/ILibraryManager.cs | 7 +++++++ .../IO/LibraryMonitor.cs | 2 +- .../Library/LibraryManager.cs | 17 +++++++++++++++++ .../Persistence/SqliteItemRepository.cs | 7 +++++++ 7 files changed, 40 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index f13058924e..b7e180eca0 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -148,6 +148,11 @@ namespace MediaBrowser.Api.Playback.Progressive args += " -bsf:v h264_mp4toannexb"; } + if (state.RunTimeTicks.HasValue && state.VideoRequest.CopyTimestamps) + { + args += " -copyts -avoid_negative_ts disabled -start_at_zero"; + } + return args; } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index d52e2b37fb..3dfbdec569 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1359,7 +1359,7 @@ namespace MediaBrowser.Controller.Entities { if (!string.IsNullOrEmpty(info.Path)) { - var itemByPath = LibraryManager.RootFolder.FindByPath(info.Path); + var itemByPath = LibraryManager.FindByPath(info.Path); if (itemByPath == null) { diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index f6af123693..8b623d64ee 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -45,6 +45,8 @@ namespace MediaBrowser.Controller.Entities public string NameLessThan { get; set; } public string NameContains { get; set; } + public string Path { get; set; } + public string Person { get; set; } public string[] PersonIds { get; set; } public string[] ItemIds { get; set; } diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 1c515edd58..ff44953ef2 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -56,6 +56,13 @@ namespace MediaBrowser.Controller.Library /// Task{Person}. Person GetPerson(string name); + /// + /// Finds the by path. + /// + /// The path. + /// BaseItem. + BaseItem FindByPath(string path); + /// /// Gets the artist. /// diff --git a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs index 5d0c90ccf3..0559e08ea0 100644 --- a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs +++ b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs @@ -664,7 +664,7 @@ namespace MediaBrowser.Server.Implementations.IO while (item == null && !string.IsNullOrEmpty(path)) { - item = LibraryManager.RootFolder.FindByPath(path); + item = LibraryManager.FindByPath(path); path = Path.GetDirectoryName(path); } diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 333b1fbe93..f0ee364b43 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -788,6 +788,23 @@ namespace MediaBrowser.Server.Implementations.Library return _userRootFolder; } + public BaseItem FindByPath(string path) + { + var query = new InternalItemsQuery + { + Path = path + }; + + var items = GetItemIds(query).Select(GetItemById).Where(i => i != null).ToArray(); + + if (items.Length == 1) + { + return items[0]; + } + + return RootFolder.FindByPath(path); + } + /// /// Gets a Person /// diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 697ec22716..cd439d1f27 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -130,6 +130,7 @@ namespace MediaBrowser.Server.Implementations.Persistence "create table if not exists TypedBaseItems (guid GUID primary key, type TEXT, data BLOB, ParentId GUID)", "create index if not exists idx_TypedBaseItems on TypedBaseItems(guid)", + "create index if not exists idx_PathTypedBaseItems on TypedBaseItems(Path)", "create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)", "create table if not exists AncestorIds (ItemId GUID, AncestorId GUID, AncestorIdText TEXT, PRIMARY KEY (ItemId, AncestorId))", @@ -1804,6 +1805,12 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.Parameters.Add(cmd, "@ParentId", DbType.Guid).Value = query.ParentId.Value; } + if (!string.IsNullOrWhiteSpace(query.Path)) + { + whereClauses.Add("Path=@Path"); + cmd.Parameters.Add(cmd, "@Path", DbType.String).Value = query.Path; + } + if (query.MinEndDate.HasValue) { whereClauses.Add("EndDate>=@MinEndDate"); From 6b1f786a445ae9e44d4d5c247c541892840ce8c1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 1 Mar 2016 14:43:03 -0500 Subject: [PATCH 2/4] update FindByPath --- .../Library/LibraryManager.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index f0ee364b43..721603efec 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -795,12 +795,18 @@ namespace MediaBrowser.Server.Implementations.Library Path = path }; + // Only use the database result if there's exactly one item, otherwise we run the risk of returning old data that hasn't been cleaned yet. var items = GetItemIds(query).Select(GetItemById).Where(i => i != null).ToArray(); if (items.Length == 1) { return items[0]; } + + if (items.Length == 0) + { + return null; + } return RootFolder.FindByPath(path); } From b2d922e305cb4c790585e404adcbf7c7465e02cb Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 1 Mar 2016 22:59:23 -0500 Subject: [PATCH 3/4] switch collapsible --- MediaBrowser.Providers/Folders/DefaultImageProvider.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/MediaBrowser.Providers/Folders/DefaultImageProvider.cs b/MediaBrowser.Providers/Folders/DefaultImageProvider.cs index e3a8cc2617..ca543163d6 100644 --- a/MediaBrowser.Providers/Folders/DefaultImageProvider.cs +++ b/MediaBrowser.Providers/Folders/DefaultImageProvider.cs @@ -25,8 +25,7 @@ namespace MediaBrowser.Providers.Folders { return new List { - ImageType.Primary, - ImageType.Thumb + ImageType.Primary }; } @@ -57,13 +56,6 @@ namespace MediaBrowser.Providers.Folders ProviderName = Name, Url = url, Type = ImageType.Primary - }, - - new RemoteImageInfo - { - ProviderName = Name, - Url = url, - Type = ImageType.Thumb } }); } From e52eb2219b1410fa2fe2343cc4f1e26fcc0af98b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 1 Mar 2016 23:46:10 -0500 Subject: [PATCH 4/4] use shared usersettings --- MediaBrowser.Server.Implementations/Sync/SyncHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Sync/SyncHelper.cs b/MediaBrowser.Server.Implementations/Sync/SyncHelper.cs index b6242950ff..fb4e0c6be0 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncHelper.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncHelper.cs @@ -10,11 +10,11 @@ namespace MediaBrowser.Server.Implementations.Sync { if (string.Equals(quality, "medium", StringComparison.OrdinalIgnoreCase)) { - profileBitrate = Math.Min(Convert.ToInt32(profileBitrate.Value * .7), 4000000); + profileBitrate = Math.Min(profileBitrate.Value, 4000000); } else if (string.Equals(quality, "low", StringComparison.OrdinalIgnoreCase)) { - profileBitrate = Math.Min(Convert.ToInt32(profileBitrate.Value * .5), 1500000); + profileBitrate = Math.Min(profileBitrate.Value, 1500000); } }