update people queries

pull/702/head
Luke Pulverenti 10 years ago
parent 8ccd82719a
commit dfa17aec70

@ -70,7 +70,12 @@ namespace MediaBrowser.Controller.Entities
public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems) public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
{ {
return inputItems.Where(GetItemFilter()); var itemsWithPerson = LibraryManager.GetItemIds(new InternalItemsQuery
{
Person = Name
});
return inputItems.Where(i => itemsWithPerson.Contains(i.Id));
} }

@ -1699,8 +1699,7 @@ namespace MediaBrowser.Controller.Entities
.Select(i => i == null ? "-1" : i.Name) .Select(i => i == null ? "-1" : i.Name)
.ToList(); .ToList();
if (!(names.Any( if (!(names.Any(v => libraryManager.GetPeople(item).Select(i => i.Name).Contains(v, StringComparer.OrdinalIgnoreCase))))
v => libraryManager.GetPeople(item).Select(i => i.Name).Contains(v, StringComparer.OrdinalIgnoreCase))))
{ {
return false; return false;
} }

@ -420,6 +420,13 @@ namespace MediaBrowser.Controller.Library
/// <returns>List&lt;PersonInfo&gt;.</returns> /// <returns>List&lt;PersonInfo&gt;.</returns>
List<PersonInfo> GetPeople(BaseItem item); List<PersonInfo> GetPeople(BaseItem item);
/// <summary>
/// Gets the people items.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>List&lt;Person&gt;.</returns>
List<Person> GetPeopleItems(BaseItem item);
/// <summary> /// <summary>
/// Gets all people names. /// Gets all people names.
/// </summary> /// </summary>
@ -433,5 +440,12 @@ namespace MediaBrowser.Controller.Library
/// <param name="people">The people.</param> /// <param name="people">The people.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
Task UpdatePeople(BaseItem item, List<PersonInfo> people); Task UpdatePeople(BaseItem item, List<PersonInfo> people);
/// <summary>
/// Gets the item ids.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>List&lt;Guid&gt;.</returns>
List<Guid> GetItemIds(InternalItemsQuery query);
} }
} }

@ -162,6 +162,13 @@ namespace MediaBrowser.Controller.Persistence
/// <param name="people">The people.</param> /// <param name="people">The people.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
Task UpdatePeople(Guid itemId, List<PersonInfo> people); Task UpdatePeople(Guid itemId, List<PersonInfo> people);
/// <summary>
/// Gets the people names.
/// </summary>
/// <param name="itemId">The item identifier.</param>
/// <returns>List&lt;System.String&gt;.</returns>
List<string> GetPeopleNames(Guid itemId);
} }
} }

@ -410,18 +410,7 @@ namespace MediaBrowser.Dlna.ContentDirectory
{ {
if (stubType.Value == StubType.People) if (stubType.Value == StubType.People)
{ {
var items = _libraryManager.GetPeople(item).Select(i => var items = _libraryManager.GetPeopleItems(item).ToArray();
{
try
{
return _libraryManager.GetPerson(i.Name);
}
catch
{
return null;
}
}).Where(i => i != null).ToArray();
var result = new QueryResult<ServerItem> var result = new QueryResult<ServerItem>
{ {

@ -59,9 +59,13 @@ namespace MediaBrowser.Providers.People
// Avoid implicitly captured closure // Avoid implicitly captured closure
var itemName = item.Name; var itemName = item.Name;
var seriesWithPerson = _libraryManager.RootFolder var seriesWithPerson = _libraryManager.GetItems(new InternalItemsQuery
.GetRecursiveChildren(i => i is Series && !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb)) && _libraryManager.GetPeople(i).Any(p => string.Equals(p.Name, itemName, StringComparison.OrdinalIgnoreCase))) {
.Cast<Series>() IncludeItemTypes = new[] { typeof(Series).Name },
Person = itemName
}).Items.Cast<Series>()
.Where(i => !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb)))
.ToList(); .ToList();
var infos = seriesWithPerson.Select(i => GetImageFromSeriesData(i, item.Name, cancellationToken)) var infos = seriesWithPerson.Select(i => GetImageFromSeriesData(i, item.Name, cancellationToken))

@ -1223,6 +1223,11 @@ namespace MediaBrowser.Server.Implementations.Library
}; };
} }
public List<Guid> GetItemIds(InternalItemsQuery query)
{
return ItemRepository.GetItemIdsList(query);
}
/// <summary> /// <summary>
/// Gets the intros. /// Gets the intros.
/// </summary> /// </summary>
@ -2057,12 +2062,28 @@ namespace MediaBrowser.Server.Implementations.Library
} }
} }
public List<PersonInfo> GetPeople(BaseItem item) public List<PersonInfo> GetPeople(BaseItem item)
{ {
return item.People ?? ItemRepository.GetPeople(item.Id); return item.People ?? ItemRepository.GetPeople(item.Id);
} }
public List<Person> 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<PersonInfo> GetAllPeople() public List<PersonInfo> GetAllPeople()
{ {
return RootFolder.GetRecursiveChildren() return RootFolder.GetRecursiveChildren()

@ -1,6 +1,7 @@
using System.Runtime.Serialization; using System.Runtime.Serialization;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
@ -739,9 +740,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
{ {
cmd.CommandText = "select guid from TypedBaseItems"; cmd.CommandText = "select guid from TypedBaseItems";
var whereClauses = GetWhereClauses(query, cmd, false); var whereClauses = GetWhereClauses(query, cmd, true);
whereClauses = GetWhereClauses(query, cmd, true);
var whereText = whereClauses.Count == 0 ? var whereText = whereClauses.Count == 0 ?
string.Empty : 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 (addPaging)
{ {
if (query.StartIndex.HasValue && query.StartIndex.Value > 0) 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(LiveTvChannel).Name, new []{typeof(LiveTvChannel).FullName}},
{typeof(LiveTvVideoRecording).Name, new []{typeof(LiveTvVideoRecording).FullName}}, {typeof(LiveTvVideoRecording).Name, new []{typeof(LiveTvVideoRecording).FullName}},
{typeof(LiveTvAudioRecording).Name, new []{typeof(LiveTvAudioRecording).FullName}}, {typeof(LiveTvAudioRecording).Name, new []{typeof(LiveTvAudioRecording).FullName}},
{typeof(Series).Name, new []{typeof(Series).FullName}},
{"Recording", new []{typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName}} {"Recording", new []{typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName}}
}; };
@ -1127,6 +1133,34 @@ namespace MediaBrowser.Server.Implementations.Persistence
return _mediaStreamsRepository.SaveMediaStreams(id, streams, cancellationToken); return _mediaStreamsRepository.SaveMediaStreams(id, streams, cancellationToken);
} }
public List<string> 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<string>();
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
{
while (reader.Read())
{
list.Add(reader.GetString(0));
}
}
return list;
}
}
public List<PersonInfo> GetPeople(Guid itemId) public List<PersonInfo> GetPeople(Guid itemId)
{ {

@ -8,7 +8,6 @@ using MediaBrowser.Model.Logging;
using MediaBrowser.XbmcMetadata.Configuration; using MediaBrowser.XbmcMetadata.Configuration;
using MediaBrowser.XbmcMetadata.Savers; using MediaBrowser.XbmcMetadata.Savers;
using System; using System;
using System.Linq;
namespace MediaBrowser.XbmcMetadata namespace MediaBrowser.XbmcMetadata
{ {
@ -50,7 +49,11 @@ namespace MediaBrowser.XbmcMetadata
return; return;
} }
var items = _libraryManager.RootFolder.GetRecursiveChildren(person.GetItemFilter()); var items = _libraryManager.GetItems(new InternalItemsQuery
{
Person = person.Name
}).Items;
foreach (var item in items) foreach (var item in items)
{ {

@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
//[assembly: AssemblyVersion("3.0.*")] [assembly: AssemblyVersion("3.0.*")]
[assembly: AssemblyVersion("3.0.5666.0")] //[assembly: AssemblyVersion("3.0.5666.0")]

Loading…
Cancel
Save