update indexes

pull/702/head
Luke Pulverenti 9 years ago
parent 02bba9984f
commit 6f88eb9aa6

@ -128,7 +128,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
connection.RunQueries(new[] connection.RunQueries(new[]
{ {
"pragma temp_store = memory", "pragma temp_store = memory",
"PRAGMA main.locking_mode=EXCLUSIVE" "pragma default_temp_store = memory",
"PRAGMA locking_mode=EXCLUSIVE"
}, Logger); }, Logger);
@ -139,7 +140,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database /// Opens the connection to the database
/// </summary> /// </summary>
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task Initialize() public async Task Initialize(SqliteUserDataRepository userDataRepo)
{ {
_connection = await CreateConnection(false).ConfigureAwait(false); _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 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 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 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 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)", "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 idxPeopleItemId1 on People(ItemId,ListOrder)",
"create index if not exists idxPeopleName on People(Name)", "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))", "create table if not exists "+ChaptersTableName+" (ItemId GUID, ChapterIndex INT, StartPositionTicks BIGINT, Name TEXT, ImagePath TEXT, PRIMARY KEY (ItemId, ChapterIndex))",
createMediaStreamsTableCommand, createMediaStreamsTableCommand,
"create index if not exists idx_mediastreams1 on mediastreams(ItemId)", "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"); _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text");
string[] postQueries = 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_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_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)", // covering index
"create index if not exists idx_TypeTopParentId on TypedBaseItems(Type,TopParentId)", "create index if not exists idx_TopParentIdGuid on TypedBaseItems(TopParentId,Guid)",
// live tv programs // live tv programs
"create index if not exists idx_TypeTopParentIdStartDate on TypedBaseItems(Type,TopParentId,StartDate)", "create index if not exists idx_TypeTopParentIdStartDate on TypedBaseItems(Type,TopParentId,StartDate)",
// used by movie suggestions // used by movie suggestions
"create index if not exists idx_TypeTopParentIdGroup on TypedBaseItems(Type,TopParentId,PresentationUniqueKey)", "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_TypeTopParentId5 on TypedBaseItems(TopParentId,IsVirtualItem)",
"create index if not exists idx_TypeTopParentId6 on TypedBaseItems(TopParentId,Type,IsVirtualItem,PresentationUniqueKey)",
// latest items // latest items
"create index if not exists idx_TypeTopParentId9 on TypedBaseItems(TopParentId,Type,IsVirtualItem,PresentationUniqueKey,DateCreated)", "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 // items by name
"create index if not exists idx_ItemValues3 on ItemValues(ItemId,Type,CleanValue)", "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)", // covering index
"create index if not exists idx_UserDataKeys2 on UserDataKeys(ItemId,Priority)" "create index if not exists idx_UserDataKeys3 on UserDataKeys(ItemId,Priority,UserDataKey)"
}; };
_connection.RunQueries(postQueries, Logger); _connection.RunQueries(postQueries, Logger);
@ -306,6 +327,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
new MediaStreamColumns(_connection, Logger).AddColumns(); new MediaStreamColumns(_connection, Logger).AddColumns();
DataExtensions.Attach(_connection, Path.Combine(_config.ApplicationPaths.DataPath, "userdata_v2.db"), "UserDataDb"); 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 = private readonly string[] _retriveItemColumns =
@ -1819,7 +1842,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
var slowThreshold = 1000; var slowThreshold = 1000;
#if DEBUG #if DEBUG
slowThreshold = 80; slowThreshold = 60;
#endif #endif
if (elapsed >= slowThreshold) if (elapsed >= slowThreshold)

@ -56,17 +56,21 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database /// Opens the connection to the database
/// </summary> /// </summary>
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task Initialize() public async Task Initialize(IDbConnection connection)
{ {
_connection = await CreateConnection(false).ConfigureAwait(false); _connection = connection;
string[] queries = { 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)", "drop index if exists UserDataDb.idx_userdata",
"create unique index if not exists userdataindex on userdata (key, userId)", "drop index if exists UserDataDb.idx_userdata1",
"create index if not exists userdataindex1 on userdata (key, userId)", "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 //pragmas
"pragma temp_store = memory", "pragma temp_store = memory",

@ -587,8 +587,11 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance(SubtitleEncoder); RegisterSingleInstance(SubtitleEncoder);
await displayPreferencesRepo.Initialize().ConfigureAwait(false); 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; ((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
await ConfigureNotificationsRepository().ConfigureAwait(false); await ConfigureNotificationsRepository().ConfigureAwait(false);
progress.Report(100); progress.Report(100);
@ -751,18 +754,6 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance(NotificationsRepository); RegisterSingleInstance(NotificationsRepository);
} }
/// <summary>
/// Configures the user data repositories.
/// </summary>
private async Task ConfigureUserDataRepositories()
{
var repo = new SqliteUserDataRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector());
await repo.Initialize().ConfigureAwait(false);
((UserDataManager)UserDataManager).Repository = repo;
}
/// <summary> /// <summary>
/// Dirty hacks /// Dirty hacks
/// </summary> /// </summary>

Loading…
Cancel
Save