From dfa17aec70652d8a21d43c889f08f8c0fd805d09 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 6 Jul 2015 22:25:23 -0400 Subject: [PATCH] update people queries --- MediaBrowser.Controller/Entities/Person.cs | 7 +++- .../Entities/UserViewBuilder.cs | 3 +- .../Library/ILibraryManager.cs | 14 +++++++ .../Persistence/IItemRepository.cs | 7 ++++ .../ContentDirectory/ControlHandler.cs | 13 +----- .../People/TvdbPersonImageProvider.cs | 10 +++-- .../Library/LibraryManager.cs | 23 ++++++++++- .../Persistence/SqliteItemRepository.cs | 40 +++++++++++++++++-- MediaBrowser.XbmcMetadata/EntryPoint.cs | 7 +++- SharedVersion.cs | 4 +- 10 files changed, 102 insertions(+), 26 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Person.cs b/MediaBrowser.Controller/Entities/Person.cs index 390fcaf80..535574ad9 100644 --- a/MediaBrowser.Controller/Entities/Person.cs +++ b/MediaBrowser.Controller/Entities/Person.cs @@ -70,7 +70,12 @@ namespace MediaBrowser.Controller.Entities public IEnumerable GetTaggedItems(IEnumerable inputItems) { - return inputItems.Where(GetItemFilter()); + var itemsWithPerson = LibraryManager.GetItemIds(new InternalItemsQuery + { + Person = Name + }); + + return inputItems.Where(i => itemsWithPerson.Contains(i.Id)); } diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 41e5406e1..7bbe5c39c 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1699,8 +1699,7 @@ namespace MediaBrowser.Controller.Entities .Select(i => i == null ? "-1" : i.Name) .ToList(); - if (!(names.Any( - v => libraryManager.GetPeople(item).Select(i => i.Name).Contains(v, StringComparer.OrdinalIgnoreCase)))) + if (!(names.Any(v => libraryManager.GetPeople(item).Select(i => i.Name).Contains(v, StringComparer.OrdinalIgnoreCase)))) { return false; } diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 92028cc1a..58c696d55 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -420,6 +420,13 @@ namespace MediaBrowser.Controller.Library /// List<PersonInfo>. List GetPeople(BaseItem item); + /// + /// Gets the people items. + /// + /// The item. + /// List<Person>. + List GetPeopleItems(BaseItem item); + /// /// Gets all people names. /// @@ -433,5 +440,12 @@ namespace MediaBrowser.Controller.Library /// The people. /// Task. Task UpdatePeople(BaseItem item, List people); + + /// + /// Gets the item ids. + /// + /// The query. + /// List<Guid>. + List GetItemIds(InternalItemsQuery query); } } \ No newline at end of file diff --git a/MediaBrowser.Controller/Persistence/IItemRepository.cs b/MediaBrowser.Controller/Persistence/IItemRepository.cs index fba5f4c03..a91a7d3ac 100644 --- a/MediaBrowser.Controller/Persistence/IItemRepository.cs +++ b/MediaBrowser.Controller/Persistence/IItemRepository.cs @@ -162,6 +162,13 @@ namespace MediaBrowser.Controller.Persistence /// The people. /// Task. Task UpdatePeople(Guid itemId, List people); + + /// + /// Gets the people names. + /// + /// The item identifier. + /// List<System.String>. + List GetPeopleNames(Guid itemId); } } diff --git a/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs b/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs index 6771fd1ab..46c0f48e2 100644 --- a/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs +++ b/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs @@ -410,18 +410,7 @@ namespace MediaBrowser.Dlna.ContentDirectory { if (stubType.Value == StubType.People) { - var items = _libraryManager.GetPeople(item).Select(i => - { - try - { - return _libraryManager.GetPerson(i.Name); - } - catch - { - return null; - } - - }).Where(i => i != null).ToArray(); + var items = _libraryManager.GetPeopleItems(item).ToArray(); var result = new QueryResult { diff --git a/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs b/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs index 38913ff42..86e2cfaf7 100644 --- a/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs +++ b/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs @@ -59,9 +59,13 @@ namespace MediaBrowser.Providers.People // Avoid implicitly captured closure var itemName = item.Name; - var seriesWithPerson = _libraryManager.RootFolder - .GetRecursiveChildren(i => i is Series && !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb)) && _libraryManager.GetPeople(i).Any(p => string.Equals(p.Name, itemName, StringComparison.OrdinalIgnoreCase))) - .Cast() + var seriesWithPerson = _libraryManager.GetItems(new InternalItemsQuery + { + IncludeItemTypes = new[] { typeof(Series).Name }, + Person = itemName + + }).Items.Cast() + .Where(i => !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb))) .ToList(); var infos = seriesWithPerson.Select(i => GetImageFromSeriesData(i, item.Name, cancellationToken)) diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index c5171e323..a4be54f27 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1223,6 +1223,11 @@ namespace MediaBrowser.Server.Implementations.Library }; } + public List GetItemIds(InternalItemsQuery query) + { + return ItemRepository.GetItemIdsList(query); + } + /// /// Gets the intros. /// @@ -2057,12 +2062,28 @@ namespace MediaBrowser.Server.Implementations.Library } } - public List GetPeople(BaseItem item) { return item.People ?? ItemRepository.GetPeople(item.Id); } + public List GetPeopleItems(BaseItem item) + { + return ItemRepository.GetPeopleNames(item.Id).Select(i => + { + try + { + return GetPerson(i); + } + catch (Exception ex) + { + _logger.ErrorException("Error getting person", ex); + return null; + } + + }).Where(i => i != null).ToList(); + } + public List GetAllPeople() { return RootFolder.GetRecursiveChildren() diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 9778e3c32..a247bbbe3 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -1,6 +1,7 @@ using System.Runtime.Serialization; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; @@ -739,9 +740,7 @@ namespace MediaBrowser.Server.Implementations.Persistence { cmd.CommandText = "select guid from TypedBaseItems"; - var whereClauses = GetWhereClauses(query, cmd, false); - - whereClauses = GetWhereClauses(query, cmd, true); + var whereClauses = GetWhereClauses(query, cmd, true); var whereText = whereClauses.Count == 0 ? string.Empty : @@ -914,6 +913,12 @@ namespace MediaBrowser.Server.Implementations.Persistence } } + if (!string.IsNullOrWhiteSpace(query.Person)) + { + whereClauses.Add("Guid in (select ItemId from People where Name=@PersonName)"); + cmd.Parameters.Add(cmd, "@PersonName", DbType.String).Value = query.Person; + } + if (addPaging) { if (query.StartIndex.HasValue && query.StartIndex.Value > 0) @@ -938,6 +943,7 @@ namespace MediaBrowser.Server.Implementations.Persistence {typeof(LiveTvChannel).Name, new []{typeof(LiveTvChannel).FullName}}, {typeof(LiveTvVideoRecording).Name, new []{typeof(LiveTvVideoRecording).FullName}}, {typeof(LiveTvAudioRecording).Name, new []{typeof(LiveTvAudioRecording).FullName}}, + {typeof(Series).Name, new []{typeof(Series).FullName}}, {"Recording", new []{typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName}} }; @@ -1127,6 +1133,34 @@ namespace MediaBrowser.Server.Implementations.Persistence return _mediaStreamsRepository.SaveMediaStreams(id, streams, cancellationToken); } + public List GetPeopleNames(Guid itemId) + { + if (itemId == Guid.Empty) + { + throw new ArgumentNullException("itemId"); + } + + CheckDisposed(); + + using (var cmd = _connection.CreateCommand()) + { + cmd.CommandText = "select Distinct Name from People where ItemId=@ItemId order by ListOrder"; + + cmd.Parameters.Add(cmd, "@ItemId", DbType.Guid).Value = itemId; + + var list = new List(); + + using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) + { + while (reader.Read()) + { + list.Add(reader.GetString(0)); + } + } + + return list; + } + } public List GetPeople(Guid itemId) { diff --git a/MediaBrowser.XbmcMetadata/EntryPoint.cs b/MediaBrowser.XbmcMetadata/EntryPoint.cs index d07633268..c3bc6e30f 100644 --- a/MediaBrowser.XbmcMetadata/EntryPoint.cs +++ b/MediaBrowser.XbmcMetadata/EntryPoint.cs @@ -8,7 +8,6 @@ using MediaBrowser.Model.Logging; using MediaBrowser.XbmcMetadata.Configuration; using MediaBrowser.XbmcMetadata.Savers; using System; -using System.Linq; namespace MediaBrowser.XbmcMetadata { @@ -50,7 +49,11 @@ namespace MediaBrowser.XbmcMetadata return; } - var items = _libraryManager.RootFolder.GetRecursiveChildren(person.GetItemFilter()); + var items = _libraryManager.GetItems(new InternalItemsQuery + { + Person = person.Name + + }).Items; foreach (var item in items) { diff --git a/SharedVersion.cs b/SharedVersion.cs index 607b1a880..092708e9d 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,4 +1,4 @@ using System.Reflection; -//[assembly: AssemblyVersion("3.0.*")] -[assembly: AssemblyVersion("3.0.5666.0")] +[assembly: AssemblyVersion("3.0.*")] +//[assembly: AssemblyVersion("3.0.5666.0")]