From 02bba9984f0c5159c1de2a506c8d51351346acae Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 23 Jun 2016 23:23:31 -0400 Subject: [PATCH 1/3] Add Series and Season channel folder types --- MediaBrowser.Model/Channels/ChannelFolderType.cs | 6 +++++- .../Channels/ChannelManager.cs | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Model/Channels/ChannelFolderType.cs b/MediaBrowser.Model/Channels/ChannelFolderType.cs index c456af69a..7c97afd02 100644 --- a/MediaBrowser.Model/Channels/ChannelFolderType.cs +++ b/MediaBrowser.Model/Channels/ChannelFolderType.cs @@ -8,6 +8,10 @@ namespace MediaBrowser.Model.Channels PhotoAlbum = 2, - MusicArtist = 3 + MusicArtist = 3, + + Series = 4, + + Season = 5 } } \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index aac5ddcaf..569b0b374 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -1258,6 +1258,14 @@ namespace MediaBrowser.Server.Implementations.Channels { item = GetItemById(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); } + else if (info.FolderType == ChannelFolderType.Series) + { + item = GetItemById(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); + } + else if (info.FolderType == ChannelFolderType.Season) + { + item = GetItemById(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); + } else { item = GetItemById(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew); From 6f88eb9aa610445af73b6f648653e2619dd244c0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 24 Jun 2016 02:32:51 -0400 Subject: [PATCH 2/3] update indexes --- .../Persistence/SqliteItemRepository.cs | 51 ++++++++++++++----- .../Persistence/SqliteUserDataRepository.cs | 16 +++--- .../ApplicationHost.cs | 19 ++----- 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 784766071..4a280389c 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -128,7 +128,8 @@ namespace MediaBrowser.Server.Implementations.Persistence connection.RunQueries(new[] { "pragma temp_store = memory", - "PRAGMA main.locking_mode=EXCLUSIVE" + "pragma default_temp_store = memory", + "PRAGMA locking_mode=EXCLUSIVE" }, Logger); @@ -139,7 +140,7 @@ namespace MediaBrowser.Server.Implementations.Persistence /// Opens the connection to the database /// /// Task. - public async Task Initialize() + public async Task Initialize(SqliteUserDataRepository userDataRepo) { _connection = await CreateConnection(false).ConfigureAwait(false); @@ -163,18 +164,22 @@ namespace MediaBrowser.Server.Implementations.Persistence "create index if not exists idx_ItemValues2 on ItemValues(ItemId,Type)", "create table if not exists ProviderIds (ItemId GUID, Name TEXT, Value TEXT, PRIMARY KEY (ItemId, Name))", - "create index if not exists Idx_ProviderIds on ProviderIds(ItemId)", + // covering index + "create index if not exists Idx_ProviderIds1 on ProviderIds(ItemId,Name,Value)", "create table if not exists Images (ItemId GUID NOT NULL, Path TEXT NOT NULL, ImageType INT NOT NULL, DateModified DATETIME, IsPlaceHolder BIT NOT NULL, SortOrder INT)", "create index if not exists idx_Images on Images(ItemId)", "create table if not exists People (ItemId GUID, Name TEXT NOT NULL, Role TEXT, PersonType TEXT, SortOrder int, ListOrder int)", + + "drop index if exists idxPeopleItemId", "create index if not exists idxPeopleItemId1 on People(ItemId,ListOrder)", "create index if not exists idxPeopleName on People(Name)", "create table if not exists "+ChaptersTableName+" (ItemId GUID, ChapterIndex INT, StartPositionTicks BIGINT, Name TEXT, ImagePath TEXT, PRIMARY KEY (ItemId, ChapterIndex))", createMediaStreamsTableCommand, + "create index if not exists idx_mediastreams1 on mediastreams(ItemId)", }; @@ -266,24 +271,39 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); string[] postQueries = + { + // obsolete + "drop index if exists idx_TypedBaseItems", + "drop index if exists idx_mediastreams", + "drop index if exists idx_"+ChaptersTableName, + "drop index if exists idx_UserDataKeys1", + "drop index if exists idx_UserDataKeys2", + "drop index if exists idx_TypeTopParentId3", + "drop index if exists idx_TypeTopParentId2", + "drop index if exists idx_TypeTopParentId4", + "drop index if exists idx_Type", + "drop index if exists idx_TypeTopParentId", + "drop index if exists idx_GuidType", + "drop index if exists idx_TopParentId", + "drop index if exists idx_TypeTopParentId6", + "drop index if exists idx_ItemValues2", + "drop index if exists Idx_ProviderIds", + "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_GuidTypeIsFolderIsVirtualItem on TypedBaseItems(Guid,Type,IsFolder,IsVirtualItem)", + //"create index if not exists idx_GuidMediaTypeIsFolderIsVirtualItem on TypedBaseItems(Guid,MediaType,IsFolder,IsVirtualItem)", "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)", + + // covering index + "create index if not exists idx_TopParentIdGuid on TypedBaseItems(TopParentId,Guid)", // live tv programs "create index if not exists idx_TypeTopParentIdStartDate on TypedBaseItems(Type,TopParentId,StartDate)", // used by movie suggestions "create index if not exists idx_TypeTopParentIdGroup on TypedBaseItems(Type,TopParentId,PresentationUniqueKey)", - "create index if not exists idx_TypeTopParentId2 on TypedBaseItems(TopParentId,MediaType,IsVirtualItem)", - "create index if not exists idx_TypeTopParentId3 on TypedBaseItems(TopParentId,IsFolder,IsVirtualItem)", - "create index if not exists idx_TypeTopParentId4 on TypedBaseItems(TopParentId,Type,IsVirtualItem)", "create index if not exists idx_TypeTopParentId5 on TypedBaseItems(TopParentId,IsVirtualItem)", - "create index if not exists idx_TypeTopParentId6 on TypedBaseItems(TopParentId,Type,IsVirtualItem,PresentationUniqueKey)", // latest items "create index if not exists idx_TypeTopParentId9 on TypedBaseItems(TopParentId,Type,IsVirtualItem,PresentationUniqueKey,DateCreated)", @@ -294,9 +314,10 @@ namespace MediaBrowser.Server.Implementations.Persistence // items by name "create index if not exists idx_ItemValues3 on ItemValues(ItemId,Type,CleanValue)", + "create index if not exists idx_ItemValues4 on ItemValues(ItemId,Type,Value,CleanValue)", - //"create index if not exists idx_UserDataKeys1 on UserDataKeys(ItemId)", - "create index if not exists idx_UserDataKeys2 on UserDataKeys(ItemId,Priority)" + // covering index + "create index if not exists idx_UserDataKeys3 on UserDataKeys(ItemId,Priority,UserDataKey)" }; _connection.RunQueries(postQueries, Logger); @@ -306,6 +327,8 @@ namespace MediaBrowser.Server.Implementations.Persistence new MediaStreamColumns(_connection, Logger).AddColumns(); DataExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb"); + await userDataRepo.Initialize(_connection).ConfigureAwait(false); + //await Vacuum(_connection).ConfigureAwait(false); } private readonly string[] _retriveItemColumns = @@ -1819,7 +1842,7 @@ namespace MediaBrowser.Server.Implementations.Persistence var slowThreshold = 1000; #if DEBUG - slowThreshold = 80; + slowThreshold = 60; #endif if (elapsed >= slowThreshold) diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs index ced43a3e3..3d268cc63 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs @@ -56,17 +56,21 @@ namespace MediaBrowser.Server.Implementations.Persistence /// Opens the connection to the database /// /// Task. - public async Task Initialize() + public async Task Initialize(IDbConnection connection) { - _connection = await CreateConnection(false).ConfigureAwait(false); + _connection = connection; string[] queries = { - "create table if not exists userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)", + "create table if not exists UserDataDb.userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)", - "create index if not exists idx_userdata on userdata(key)", - "create unique index if not exists userdataindex on userdata (key, userId)", - "create index if not exists userdataindex1 on userdata (key, userId)", + "drop index if exists UserDataDb.idx_userdata", + "drop index if exists UserDataDb.idx_userdata1", + "drop index if exists UserDataDb.idx_userdata2", + "drop index if exists UserDataDb.userdataindex1", + + "create unique index if not exists UserDataDb.userdataindex on userdata (key, userId)", + "create index if not exists UserDataDb.userdataindex2 on userdata (key, userId, played)", //pragmas "pragma temp_store = memory", diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 7390fbbbc..ec1ccbff5 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -587,8 +587,11 @@ namespace MediaBrowser.Server.Startup.Common RegisterSingleInstance(SubtitleEncoder); await displayPreferencesRepo.Initialize().ConfigureAwait(false); - await ConfigureUserDataRepositories().ConfigureAwait(false); - await itemRepo.Initialize().ConfigureAwait(false); + + var userDataRepo = new SqliteUserDataRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector()); + + ((UserDataManager)UserDataManager).Repository = userDataRepo; + await itemRepo.Initialize(userDataRepo).ConfigureAwait(false); ((LibraryManager)LibraryManager).ItemRepository = ItemRepository; await ConfigureNotificationsRepository().ConfigureAwait(false); progress.Report(100); @@ -751,18 +754,6 @@ namespace MediaBrowser.Server.Startup.Common RegisterSingleInstance(NotificationsRepository); } - /// - /// Configures the user data repositories. - /// - private async Task ConfigureUserDataRepositories() - { - var repo = new SqliteUserDataRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector()); - - await repo.Initialize().ConfigureAwait(false); - - ((UserDataManager)UserDataManager).Repository = repo; - } - /// /// Dirty hacks /// From 3950bbc0137f8306534dd960b433f2e7727dff37 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 24 Jun 2016 11:12:03 -0400 Subject: [PATCH 3/3] update sqlite --- MediaBrowser.Api/StartupWizardService.cs | 2 +- .../Persistence/SqliteItemRepository.cs | 15 ++++++++++++--- .../Persistence/SqliteUserDataRepository.cs | 7 ++++--- .../MediaBrowser.ServerApplication.csproj | 8 ++++---- MediaBrowser.ServerApplication/packages.config | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 6c58228ea..f993bc4b1 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -118,7 +118,7 @@ namespace MediaBrowser.Api config.EnableStandaloneMusicKeys = true; config.EnableCaseSensitiveItemIds = true; config.EnableFolderView = true; - config.SchemaVersion = 95; + config.SchemaVersion = 96; } public void Post(UpdateStartupConfiguration request) diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 4a280389c..6d067e345 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Persistence private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedTagsCommand; - public const int LatestSchemaVersion = 95; + public const int LatestSchemaVersion = 96; /// /// Initializes a new instance of the class. @@ -266,6 +266,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "Album", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "IsVirtualItem", "BIT"); _connection.AddColumn(Logger, "TypedBaseItems", "SeriesName", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text"); _connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT"); _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); @@ -510,7 +511,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "DateLastMediaAdded", "Album", "IsVirtualItem", - "SeriesName" + "SeriesName", + "UserDataKey" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -939,6 +941,8 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = null; } + _saveItemCommand.GetParameter(index++).Value = item.GetUserDataKeys().FirstOrDefault(); + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -1737,6 +1741,11 @@ namespace MediaBrowser.Server.Implementations.Persistence return string.Empty; } + if (_config.Configuration.SchemaVersion >= 96) + { + return " left join UserDataDb.UserData on UserDataKey=UserDataDb.UserData.Key And (UserId=@UserId)"; + } + return " left join UserDataDb.UserData on (select UserDataKey from UserDataKeys where ItemId=Guid order by Priority LIMIT 1)=UserDataDb.UserData.Key And (UserId=@UserId)"; } @@ -1842,7 +1851,7 @@ namespace MediaBrowser.Server.Implementations.Persistence var slowThreshold = 1000; #if DEBUG - slowThreshold = 60; + slowThreshold = 50; #endif if (elapsed >= slowThreshold) diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs index 3d268cc63..90dbd7770 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteUserDataRepository.cs @@ -336,18 +336,19 @@ namespace MediaBrowser.Server.Implementations.Persistence using (var cmd = _connection.CreateCommand()) { var index = 0; - var excludeIds = new List(); + var userdataKeys = new List(); var builder = new StringBuilder(); foreach (var key in keys) { var paramName = "@Key" + index; - excludeIds.Add("Key =" + paramName); + userdataKeys.Add("Key =" + paramName); cmd.Parameters.Add(cmd, paramName, DbType.String).Value = key; builder.Append(" WHEN Key=" + paramName + " THEN " + index); index++; + break; } - var keyText = string.Join(" OR ", excludeIds.ToArray()); + var keyText = string.Join(" OR ", userdataKeys.ToArray()); cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@userId AND (" + keyText + ") "; diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index 35660b2b1..fcd6f7faf 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -83,8 +83,8 @@ - - ..\packages\System.Data.SQLite.Core.1.0.101.0\lib\net46\System.Data.SQLite.dll + + ..\packages\System.Data.SQLite.Core.1.0.102.0\lib\net46\System.Data.SQLite.dll True @@ -1112,12 +1112,12 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - +