From 009abaf9beb85b3f2d944d82477cc9ce636138c8 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 24 May 2018 17:51:05 -0400 Subject: [PATCH] Fixed: Rare timing issue on first-use causing duplicate naming config (#2790) Fixes #2773 --- .../Migration/148_remove_extra_naming_config.cs | 15 +++++++++++++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + .../Organizer/NamingConfigService.cs | 14 +++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/148_remove_extra_naming_config.cs diff --git a/src/NzbDrone.Core/Datastore/Migration/148_remove_extra_naming_config.cs b/src/NzbDrone.Core/Datastore/Migration/148_remove_extra_naming_config.cs new file mode 100644 index 000000000..a5b41cb68 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/148_remove_extra_naming_config.cs @@ -0,0 +1,15 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(148)] + public class remove_extra_naming_config : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + // Remove all but 1 NamingConfig + Execute.Sql("DELETE FROM NamingConfig WHERE ID NOT IN(SELECT ID FROM NamingConfig LIMIT 1)"); + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 688604d79..0e225f074 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -125,6 +125,7 @@ + diff --git a/src/NzbDrone.Core/Organizer/NamingConfigService.cs b/src/NzbDrone.Core/Organizer/NamingConfigService.cs index 1cbe993dc..8cd9d3234 100644 --- a/src/NzbDrone.Core/Organizer/NamingConfigService.cs +++ b/src/NzbDrone.Core/Organizer/NamingConfigService.cs @@ -21,8 +21,16 @@ namespace NzbDrone.Core.Organizer if (config == null) { - _repository.Insert(NamingConfig.Default); - config = _repository.Single(); + lock (_repository) + { + config = _repository.SingleOrDefault(); + + if (config == null) + { + _repository.Insert(NamingConfig.Default); + config = _repository.Single(); + } + } } return config; @@ -33,4 +41,4 @@ namespace NzbDrone.Core.Organizer _repository.Upsert(namingConfig); } } -} \ No newline at end of file +}