add userdata index

pull/702/head
Luke Pulverenti 9 years ago
parent f58a919488
commit e69f7b757f

@ -1276,26 +1276,22 @@ namespace MediaBrowser.Server.Implementations.Dto
{ {
dto.Artists = hasArtist.Artists; dto.Artists = hasArtist.Artists;
dto.ArtistItems = hasArtist var artistItems = _libraryManager.GetArtists(new InternalItemsQuery
.Artists
.Select(i =>
{ {
try EnableTotalRecordCount = false,
ItemIds = new[] { item.Id.ToString("N") }
});
dto.ArtistItems = artistItems.Items
.Select(i =>
{ {
var artist = _libraryManager.GetArtist(i); var artist = i.Item1;
return new NameIdPair return new NameIdPair
{ {
Name = artist.Name, Name = artist.Name,
Id = artist.Id.ToString("N") Id = artist.Id.ToString("N")
}; };
}
catch (Exception ex)
{
_logger.ErrorException("Error getting artist", ex);
return null;
}
}) })
.Where(i => i != null)
.ToList(); .ToList();
} }
@ -1304,26 +1300,22 @@ namespace MediaBrowser.Server.Implementations.Dto
{ {
dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault();
dto.AlbumArtists = hasAlbumArtist var artistItems = _libraryManager.GetAlbumArtists(new InternalItemsQuery
.AlbumArtists
.Select(i =>
{ {
try EnableTotalRecordCount = false,
ItemIds = new[] { item.Id.ToString("N") }
});
dto.ArtistItems = artistItems.Items
.Select(i =>
{ {
var artist = _libraryManager.GetArtist(i); var artist = i.Item1;
return new NameIdPair return new NameIdPair
{ {
Name = artist.Name, Name = artist.Name,
Id = artist.Id.ToString("N") Id = artist.Id.ToString("N")
}; };
}
catch (Exception ex)
{
_logger.ErrorException("Error getting album artist", ex);
return null;
}
}) })
.Where(i => i != null)
.ToList(); .ToList();
} }
@ -1604,7 +1596,7 @@ namespace MediaBrowser.Server.Implementations.Dto
{ {
IsFolder = false, IsFolder = false,
Recursive = true, Recursive = true,
ExcludeLocationTypes = new[] {LocationType.Virtual}, ExcludeLocationTypes = new[] { LocationType.Virtual },
User = user User = user
}).ConfigureAwait(false); }).ConfigureAwait(false);

@ -944,9 +944,7 @@ namespace MediaBrowser.Server.Implementations.Library
private T CreateItemByName<T>(string path, string name) private T CreateItemByName<T>(string path, string name)
where T : BaseItem, new() where T : BaseItem, new()
{ {
var isArtist = typeof(T) == typeof(MusicArtist); if (typeof(T) == typeof(MusicArtist))
if (isArtist)
{ {
var existing = GetItemList(new InternalItemsQuery var existing = GetItemList(new InternalItemsQuery
{ {
@ -1277,11 +1275,6 @@ namespace MediaBrowser.Server.Implementations.Library
return item; return item;
} }
private bool EnableCaching
{
get { return false; }
}
public IEnumerable<BaseItem> GetItemList(InternalItemsQuery query) public IEnumerable<BaseItem> GetItemList(InternalItemsQuery query)
{ {
if (query.User != null) if (query.User != null)
@ -1289,16 +1282,9 @@ namespace MediaBrowser.Server.Implementations.Library
AddUserToQuery(query, query.User); AddUserToQuery(query, query.User);
} }
if (!EnableCaching)
{
return ItemRepository.GetItemList(query); return ItemRepository.GetItemList(query);
} }
var result = ItemRepository.GetItemIdsList(query);
return result.Select(GetItemById).Where(i => i != null);
}
public QueryResult<BaseItem> QueryItems(InternalItemsQuery query) public QueryResult<BaseItem> QueryItems(InternalItemsQuery query)
{ {
if (query.User != null) if (query.User != null)
@ -1426,14 +1412,9 @@ namespace MediaBrowser.Server.Implementations.Library
SetTopParentIdsOrAncestors(query, parents); SetTopParentIdsOrAncestors(query, parents);
if (!EnableCaching)
{
return ItemRepository.GetItemList(query); return ItemRepository.GetItemList(query);
} }
return GetItemIds(query).Select(GetItemById).Where(i => i != null);
}
public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query) public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query)
{ {
if (query.Recursive && query.ParentId.HasValue) if (query.Recursive && query.ParentId.HasValue)
@ -1452,35 +1433,16 @@ namespace MediaBrowser.Server.Implementations.Library
} }
if (query.EnableTotalRecordCount) if (query.EnableTotalRecordCount)
{
if (!EnableCaching)
{ {
return ItemRepository.GetItems(query); return ItemRepository.GetItems(query);
} }
var initialResult = ItemRepository.GetItemIds(query);
return new QueryResult<BaseItem>
{
TotalRecordCount = initialResult.TotalRecordCount,
Items = initialResult.Items.Select(GetItemById).Where(i => i != null).ToArray()
};
}
if (!EnableCaching)
{
return new QueryResult<BaseItem> return new QueryResult<BaseItem>
{ {
Items = ItemRepository.GetItemList(query).ToArray() Items = ItemRepository.GetItemList(query).ToArray()
}; };
} }
return new QueryResult<BaseItem>
{
Items = ItemRepository.GetItemIdsList(query).Select(GetItemById).Where(i => i != null).ToArray()
};
}
public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query, IEnumerable<string> parentIds) public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query, IEnumerable<string> parentIds)
{ {
var parents = parentIds.Select(i => GetItemById(new Guid(i))).Where(i => i != null).ToList(); var parents = parentIds.Select(i => GetItemById(new Guid(i))).Where(i => i != null).ToList();

@ -155,8 +155,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create index if not exists idx_AncestorIds1 on AncestorIds(AncestorId)", "create index if not exists idx_AncestorIds1 on AncestorIds(AncestorId)",
"create index if not exists idx_AncestorIds2 on AncestorIds(AncestorIdText)", "create index if not exists idx_AncestorIds2 on AncestorIds(AncestorIdText)",
"create table if not exists UserDataKeys (ItemId GUID, UserDataKey TEXT, PRIMARY KEY (ItemId, UserDataKey))", "create table if not exists UserDataKeys (ItemId GUID, UserDataKey TEXT Priority INT, PRIMARY KEY (ItemId, UserDataKey))",
"create index if not exists idx_UserDataKeys1 on UserDataKeys(ItemId)", "create index if not exists idx_UserDataKeys1 on UserDataKeys(ItemId)",
"create index if not exists idx_UserDataKeys2 on UserDataKeys(ItemId,Priority)",
"create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)", "create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)",
"create index if not exists idx_ItemValues on ItemValues(ItemId)", "create index if not exists idx_ItemValues on ItemValues(ItemId)",
@ -270,6 +271,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
{ {
"create index if not exists idx_PresentationUniqueKey on TypedBaseItems(PresentationUniqueKey)", "create index if not exists idx_PresentationUniqueKey on TypedBaseItems(PresentationUniqueKey)",
"create index if not exists idx_GuidType on TypedBaseItems(Guid,Type)", "create index if not exists idx_GuidType on TypedBaseItems(Guid,Type)",
"create index if not exists idx_CleanNameType on TypedBaseItems(CleanName,Type)",
"create index if not exists idx_Type on TypedBaseItems(Type)", "create index if not exists idx_Type on TypedBaseItems(Type)",
"create index if not exists idx_TopParentId on TypedBaseItems(TopParentId)", "create index if not exists idx_TopParentId on TypedBaseItems(TopParentId)",
"create index if not exists idx_TypeTopParentId on TypedBaseItems(Type,TopParentId)", "create index if not exists idx_TypeTopParentId on TypedBaseItems(Type,TopParentId)",

Loading…
Cancel
Save