update indexes
This commit is contained in:
parent
02bba9984f
commit
6f88eb9aa6
|
@ -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
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
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)
|
||||
|
|
|
@ -56,17 +56,21 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
/// Opens the connection to the database
|
||||
/// </summary>
|
||||
/// <returns>Task.</returns>
|
||||
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",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Dirty hacks
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user