From e69f7b757f8f3782d4a0b85a641f36005301aaae Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 19 Jun 2016 23:34:47 -0400 Subject: [PATCH] add userdata index --- .../Dto/DtoService.cs | 58 ++++++++----------- .../Library/LibraryManager.cs | 48 ++------------- .../Persistence/SqliteItemRepository.cs | 4 +- 3 files changed, 33 insertions(+), 77 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 388dfd515d..a4cf90e5b0 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -1276,26 +1276,22 @@ namespace MediaBrowser.Server.Implementations.Dto { dto.Artists = hasArtist.Artists; - dto.ArtistItems = hasArtist - .Artists + var artistItems = _libraryManager.GetArtists(new InternalItemsQuery + { + EnableTotalRecordCount = false, + ItemIds = new[] { item.Id.ToString("N") } + }); + + dto.ArtistItems = artistItems.Items .Select(i => { - try - { - var artist = _libraryManager.GetArtist(i); - return new NameIdPair - { - Name = artist.Name, - Id = artist.Id.ToString("N") - }; - } - catch (Exception ex) + var artist = i.Item1; + return new NameIdPair { - _logger.ErrorException("Error getting artist", ex); - return null; - } + Name = artist.Name, + Id = artist.Id.ToString("N") + }; }) - .Where(i => i != null) .ToList(); } @@ -1304,26 +1300,22 @@ namespace MediaBrowser.Server.Implementations.Dto { dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); - dto.AlbumArtists = hasAlbumArtist - .AlbumArtists + var artistItems = _libraryManager.GetAlbumArtists(new InternalItemsQuery + { + EnableTotalRecordCount = false, + ItemIds = new[] { item.Id.ToString("N") } + }); + + dto.ArtistItems = artistItems.Items .Select(i => { - try - { - var artist = _libraryManager.GetArtist(i); - return new NameIdPair - { - Name = artist.Name, - Id = artist.Id.ToString("N") - }; - } - catch (Exception ex) + var artist = i.Item1; + return new NameIdPair { - _logger.ErrorException("Error getting album artist", ex); - return null; - } + Name = artist.Name, + Id = artist.Id.ToString("N") + }; }) - .Where(i => i != null) .ToList(); } @@ -1604,7 +1596,7 @@ namespace MediaBrowser.Server.Implementations.Dto { IsFolder = false, Recursive = true, - ExcludeLocationTypes = new[] {LocationType.Virtual}, + ExcludeLocationTypes = new[] { LocationType.Virtual }, User = user }).ConfigureAwait(false); diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index aabe704c7a..af00481001 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -944,9 +944,7 @@ namespace MediaBrowser.Server.Implementations.Library private T CreateItemByName(string path, string name) where T : BaseItem, new() { - var isArtist = typeof(T) == typeof(MusicArtist); - - if (isArtist) + if (typeof(T) == typeof(MusicArtist)) { var existing = GetItemList(new InternalItemsQuery { @@ -1277,11 +1275,6 @@ namespace MediaBrowser.Server.Implementations.Library return item; } - private bool EnableCaching - { - get { return false; } - } - public IEnumerable GetItemList(InternalItemsQuery query) { if (query.User != null) @@ -1289,14 +1282,7 @@ namespace MediaBrowser.Server.Implementations.Library AddUserToQuery(query, query.User); } - if (!EnableCaching) - { - return ItemRepository.GetItemList(query); - } - - var result = ItemRepository.GetItemIdsList(query); - - return result.Select(GetItemById).Where(i => i != null); + return ItemRepository.GetItemList(query); } public QueryResult QueryItems(InternalItemsQuery query) @@ -1426,12 +1412,7 @@ namespace MediaBrowser.Server.Implementations.Library SetTopParentIdsOrAncestors(query, parents); - if (!EnableCaching) - { - return ItemRepository.GetItemList(query); - } - - return GetItemIds(query).Select(GetItemById).Where(i => i != null); + return ItemRepository.GetItemList(query); } public QueryResult GetItemsResult(InternalItemsQuery query) @@ -1453,31 +1434,12 @@ namespace MediaBrowser.Server.Implementations.Library if (query.EnableTotalRecordCount) { - if (!EnableCaching) - { - return ItemRepository.GetItems(query); - } - - var initialResult = ItemRepository.GetItemIds(query); - - return new QueryResult - { - TotalRecordCount = initialResult.TotalRecordCount, - Items = initialResult.Items.Select(GetItemById).Where(i => i != null).ToArray() - }; - } - - if (!EnableCaching) - { - return new QueryResult - { - Items = ItemRepository.GetItemList(query).ToArray() - }; + return ItemRepository.GetItems(query); } return new QueryResult { - Items = ItemRepository.GetItemIdsList(query).Select(GetItemById).Where(i => i != null).ToArray() + Items = ItemRepository.GetItemList(query).ToArray() }; } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index e8b39a1fe3..5dae246572 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -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_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_UserDataKeys2 on UserDataKeys(ItemId,Priority)", "create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)", "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_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_TopParentId on TypedBaseItems(TopParentId)", "create index if not exists idx_TypeTopParentId on TypedBaseItems(Type,TopParentId)",