Fixed: Rare timing issue on first-use causing duplicate naming config (#2790)

Fixes #2773
This commit is contained in:
Qstick 2018-05-24 17:51:05 -04:00 committed by Leonardo Galli
parent 0d5c71d205
commit 009abaf9be
3 changed files with 27 additions and 3 deletions

View File

@ -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)");
}
}
}

View File

@ -125,6 +125,7 @@
<Compile Include="Authentication\UserRepository.cs" />
<Compile Include="Authentication\UserService.cs" />
<Compile Include="Datastore\Migration\123_create_netimport_table.cs" />
<Compile Include="Datastore\Migration\148_remove_extra_naming_config.cs" />
<Compile Include="Datastore\Migration\146_naming_config_colon_replacement_format.cs" />
<Compile Include="Datastore\Migration\143_clean_core_tv.cs" />
<Compile Include="Datastore\Migration\142_movie_extras.cs" />

View File

@ -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);
}
}
}
}