Browse Source

update migration

Luke Pulverenti 9 years ago
parent
commit
0b5b409354

+ 6 - 5
MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs

@@ -10,6 +10,7 @@ using MediaBrowser.Model.Logging;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Globalization;
+using System.Linq;
 using System.Threading;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using CommonIO;
 using CommonIO;
@@ -32,7 +33,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
         private readonly ILocalizationManager _localization;
         private readonly ILocalizationManager _localization;
         private readonly ITaskManager _taskManager;
         private readonly ITaskManager _taskManager;
 
 
-        public const int MigrationVersion = 17;
+        public const int MigrationVersion = 20;
         public static bool EnableUnavailableMessage = false;
         public static bool EnableUnavailableMessage = false;
 
 
         public CleanDatabaseScheduledTask(ILibraryManager libraryManager, IItemRepository itemRepo, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem, IHttpServer httpServer, ILocalizationManager localization, ITaskManager taskManager)
         public CleanDatabaseScheduledTask(ILibraryManager libraryManager, IItemRepository itemRepo, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem, IHttpServer httpServer, ILocalizationManager localization, ITaskManager taskManager)
@@ -66,6 +67,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
         {
         {
             OnProgress(0);
             OnProgress(0);
 
 
+            // Ensure these objects are out of the database.
+            var rootChildren = _libraryManager.RootFolder.Children.ToList();
+            rootChildren = _libraryManager.GetUserRootFolder().Children.ToList();
+
             var innerProgress = new ActionableProgress<double>();
             var innerProgress = new ActionableProgress<double>();
             innerProgress.RegisterAction(p =>
             innerProgress.RegisterAction(p =>
             {
             {
@@ -148,8 +153,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
                 if (itemId != Guid.Empty)
                 if (itemId != Guid.Empty)
                 {
                 {
-                    LogMessage(string.Format("Querying item {0}", itemId));
-
                     // Somehow some invalid data got into the db. It probably predates the boundary checking
                     // Somehow some invalid data got into the db. It probably predates the boundary checking
                     var item = _libraryManager.GetItemById(itemId);
                     var item = _libraryManager.GetItemById(itemId);
 
 
@@ -157,8 +160,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
                     {
                     {
                         try
                         try
                         {
                         {
-                            LogMessage(string.Format("Saving item {0}", itemId));
-
                             await _itemRepo.SaveItem(item, cancellationToken).ConfigureAwait(false);
                             await _itemRepo.SaveItem(item, cancellationToken).ConfigureAwait(false);
                         }
                         }
                         catch (OperationCanceledException)
                         catch (OperationCanceledException)

+ 6 - 0
MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs

@@ -583,16 +583,22 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
             CheckDisposed();
             CheckDisposed();
 
 
+            _logger.Info("SaveItems waiting on write lock");
+
             await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
             await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
 
 
             IDbTransaction transaction = null;
             IDbTransaction transaction = null;
 
 
             try
             try
             {
             {
+                _logger.Info("SaveItems creating transaction");
+                
                 transaction = _connection.BeginTransaction();
                 transaction = _connection.BeginTransaction();
 
 
                 foreach (var item in items)
                 foreach (var item in items)
                 {
                 {
+                    _logger.Info("Saving {0}", item.Id);
+                    
                     cancellationToken.ThrowIfCancellationRequested();
                     cancellationToken.ThrowIfCancellationRequested();
 
 
                     var index = 0;
                     var index = 0;

+ 2 - 2
MediaBrowser.Server.Startup.Common/ApplicationHost.cs

@@ -328,6 +328,8 @@ namespace MediaBrowser.Server.Startup.Common
             Logger.Info("Core startup complete");
             Logger.Info("Core startup complete");
             HttpServer.GlobalResponse = null;
             HttpServer.GlobalResponse = null;
 
 
+            PerformPostInitMigrations();
+
             Parallel.ForEach(GetExports<IServerEntryPoint>(), entryPoint =>
             Parallel.ForEach(GetExports<IServerEntryPoint>(), entryPoint =>
             {
             {
                 try
                 try
@@ -341,8 +343,6 @@ namespace MediaBrowser.Server.Startup.Common
             });
             });
 
 
             LogManager.RemoveConsoleOutput();
             LogManager.RemoveConsoleOutput();
-
-            PerformPostInitMigrations();
         }
         }
 
 
         public override Task Init(IProgress<double> progress)
         public override Task Init(IProgress<double> progress)

+ 1 - 1
MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs

@@ -25,7 +25,7 @@ namespace MediaBrowser.Server.Startup.Common.Migrations
                 
                 
                 Task.Run(async () =>
                 Task.Run(async () =>
                 {
                 {
-                    await Task.Delay(1000).ConfigureAwait(false);
+                    await Task.Delay(100).ConfigureAwait(false);
 
 
                     _taskManager.Execute<CleanDatabaseScheduledTask>();
                     _taskManager.Execute<CleanDatabaseScheduledTask>();
                 });
                 });