From 25b0a52ba6851ddaab6c89b0a940e9ccfba7eebb Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Sun, 24 Sep 2017 16:17:43 +0200 Subject: [PATCH] Fixed: Alternative Titles appearing multiple times. Duplicate alt titles will be deleted. Fixes #2040 --- .../Datastore/BasicRepository.cs | 2 +- .../Migration/141_fix_duplicate_alt_titles.cs | 32 +++++++++++++++++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/141_fix_duplicate_alt_titles.cs diff --git a/src/NzbDrone.Core/Datastore/BasicRepository.cs b/src/NzbDrone.Core/Datastore/BasicRepository.cs index 9c637f84a..cdc452284 100644 --- a/src/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/src/NzbDrone.Core/Datastore/BasicRepository.cs @@ -59,7 +59,7 @@ namespace NzbDrone.Core.Datastore public IEnumerable All() { - return DataMapper.Query().ToList(); + return Query.ToList(); } public int Count() diff --git a/src/NzbDrone.Core/Datastore/Migration/141_fix_duplicate_alt_titles.cs b/src/NzbDrone.Core/Datastore/Migration/141_fix_duplicate_alt_titles.cs new file mode 100644 index 000000000..ccd4889bb --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/141_fix_duplicate_alt_titles.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Data; +using FluentMigrator; +using Newtonsoft.Json.Linq; +using NzbDrone.Common.Extensions; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(141)] + public class fix_duplicate_alt_titles : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.WithConnection(RenameUrlToBaseUrl); + Alter.Table("AlternativeTitles").AlterColumn("CleanTitle").AsString().Unique(); + } + + private void RenameUrlToBaseUrl(IDbConnection conn, IDbTransaction tran) + { + using (var cmd = conn.CreateCommand()) + { + cmd.Transaction = tran; + cmd.CommandText = "DELETE FROM AlternativeTitles WHERE rowid NOT IN ( SELECT MIN(rowid) FROM AlternativeTitles GROUP BY CleanTitle )"; + + cmd.ExecuteNonQuery(); + + } + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 03beb294a..12d9023ae 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -126,6 +126,7 @@ +