diff --git a/NzbDrone.Common/CommonContainerExtentions.cs b/NzbDrone.Common/CommonContainerExtentions.cs index 10e2cf192..f75bb70f9 100644 --- a/NzbDrone.Common/CommonContainerExtentions.cs +++ b/NzbDrone.Common/CommonContainerExtentions.cs @@ -22,12 +22,10 @@ namespace NzbDrone.Common } containerBuilder.RegisterAssemblyTypes(apiAssembly) - .AsImplementedInterfaces() - .SingleInstance(); + .AsImplementedInterfaces(); containerBuilder.RegisterAssemblyTypes(apiAssembly) - .AsSelf() - .SingleInstance(); + .AsSelf(); } } } \ No newline at end of file diff --git a/NzbDrone.Core/ContainerExtensions.cs b/NzbDrone.Core/ContainerExtensions.cs index 45d8e4897..6e154e998 100644 --- a/NzbDrone.Core/ContainerExtensions.cs +++ b/NzbDrone.Core/ContainerExtensions.cs @@ -37,15 +37,15 @@ namespace NzbDrone.Core container.RegisterAssemblyTypes(assembly) .Where(t => t.IsSubclassOf(typeof(IndexerBase))) - .As().SingleInstance(); + .As(); container.RegisterAssemblyTypes(assembly) .Where(t => t.IsSubclassOf(typeof(IndexerSearchBase))) - .As().SingleInstance(); + .As(); container.RegisterAssemblyTypes(assembly) .Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase))) - .As().SingleInstance(); + .As(); } private static void InitDatabase(this ContainerBuilder container) @@ -56,7 +56,7 @@ namespace NzbDrone.Core var appDataPath = environmentProvider.GetAppDataPath(); if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath); - container.Register(c => c.Resolve().Create(environmentProvider.GetNzbDroneDatabase())).As().SingleInstance(); + container.Register(c => c.Resolve().Create(environmentProvider.GetNzbDroneDatabase())).As(); container.RegisterGeneric(typeof(BasicRepository<>)).As(typeof(IBasicRepository<>)); } diff --git a/NzbDrone.Core/Datastore/DbFactory.cs b/NzbDrone.Core/Datastore/DbFactory.cs index 256a4ad1a..aeff131a1 100644 --- a/NzbDrone.Core/Datastore/DbFactory.cs +++ b/NzbDrone.Core/Datastore/DbFactory.cs @@ -1,5 +1,4 @@ using System; -using System.Data; using System.Data.SQLite; using Marr.Data; using NzbDrone.Core.Datastore.Migration.Framework; @@ -16,9 +15,13 @@ namespace NzbDrone.Core.Datastore { private readonly IMigrationController _migrationController; - public DbFactory(IMigrationController migrationController) + static DbFactory() { TableMapping.Map(); + } + + public DbFactory(IMigrationController migrationController) + { _migrationController = migrationController; } diff --git a/NzbDrone.Core/Datastore/Migration/Framework/MigrationController.cs b/NzbDrone.Core/Datastore/Migration/Framework/MigrationController.cs index 83b3c7b5d..18cea944f 100644 --- a/NzbDrone.Core/Datastore/Migration/Framework/MigrationController.cs +++ b/NzbDrone.Core/Datastore/Migration/Framework/MigrationController.cs @@ -1,4 +1,6 @@ -using System.Reflection; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Reflection; using FluentMigrator.Runner; using FluentMigrator.Runner.Initialization; using FluentMigrator.Runner.Processors.Sqlite; @@ -14,6 +16,8 @@ namespace NzbDrone.Core.Datastore.Migration.Framework { private readonly IAnnouncer _announcer; + private static readonly HashSet MigrationCache = new HashSet(); + public MigrationController(IAnnouncer announcer) { _announcer = announcer; @@ -21,19 +25,26 @@ namespace NzbDrone.Core.Datastore.Migration.Framework public void MigrateToLatest(string connectionString, MigrationType migrationType) { - var assembly = Assembly.GetExecutingAssembly(); - - var migrationContext = new RunnerContext(_announcer) + lock (MigrationCache) { - Namespace = "NzbDrone.Core.Datastore.Migration", - ApplicationContext = migrationType - }; + if (MigrationCache.Contains(connectionString.ToLower())) return; - var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; - var factory = new SqliteProcessorFactory(); - var processor = factory.Create(connectionString, _announcer, options); - var runner = new MigrationRunner(assembly, migrationContext, processor); - runner.MigrateUp(true); + var assembly = Assembly.GetExecutingAssembly(); + + var migrationContext = new RunnerContext(_announcer) + { + Namespace = "NzbDrone.Core.Datastore.Migration", + ApplicationContext = migrationType + }; + + var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 }; + var factory = new SqliteProcessorFactory(); + var processor = factory.Create(connectionString, _announcer, options); + var runner = new MigrationRunner(assembly, migrationContext, processor); + runner.MigrateUp(true); + + MigrationCache.Add(connectionString.ToLower()); + } } } } diff --git a/NzbDrone.Update/Program.cs b/NzbDrone.Update/Program.cs index 08d6ce2c8..8411a0249 100644 --- a/NzbDrone.Update/Program.cs +++ b/NzbDrone.Update/Program.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Linq; using Autofac; using NLog; using NzbDrone.Common;