From 33ed76556f79855eee874e51e6a96ad46b5075d9 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 17 Feb 2015 22:02:24 -0800 Subject: [PATCH] Deduping tags only updates affected models --- .../Migration/079_dedupe_tagsFixture.cs | 55 +++++++++++++++++++ .../Datastore/Migration/079_dedupe_tags.cs | 3 +- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/079_dedupe_tagsFixture.cs b/src/NzbDrone.Core.Test/Datastore/Migration/079_dedupe_tagsFixture.cs index 47ac33b8a..6ce90cdc3 100644 --- a/src/NzbDrone.Core.Test/Datastore/Migration/079_dedupe_tagsFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/Migration/079_dedupe_tagsFixture.cs @@ -144,5 +144,60 @@ public void should_replace_duplicated_tag_with_proper_tag() Mocker.Resolve().Get(1).Tags.First().Should().Be(1); } + + [Test] + public void should_only_update_affected_series() + { + WithTestDb(c => + { + c.Insert.IntoTable("Series").Row(new + { + Tvdbid = 1, + TvRageId = 1, + Title = "Title1", + CleanTitle = "CleanTitle1", + Status = 1, + Images = "", + Path = "c:\\test", + Monitored = 1, + SeasonFolder = 1, + Runtime = 0, + SeriesType = 0, + UseSceneNumbering = 0, + LastInfoSync = "2000-01-01 00:00:00", + Tags = "[2]" + }); + + c.Insert.IntoTable("Series").Row(new + { + Tvdbid = 2, + TvRageId = 2, + Title = "Title2", + CleanTitle = "CleanTitle2", + Status = 1, + Images = "", + Path = "c:\\test", + Monitored = 1, + SeasonFolder = 1, + Runtime = 0, + SeriesType = 0, + UseSceneNumbering = 0, + LastInfoSync = "2000-01-01 00:00:00", + Tags = "[]" + }); + + c.Insert.IntoTable("Tags").Row(new + { + Label = "test" + }); + + c.Insert.IntoTable("Tags").Row(new + { + Label = "test" + }); + }); + + Mocker.Resolve().Get(2).Tags.Should().BeEmpty(); + } } } diff --git a/src/NzbDrone.Core/Datastore/Migration/079_dedupe_tags.cs b/src/NzbDrone.Core/Datastore/Migration/079_dedupe_tags.cs index e990a0bc7..800b10d99 100644 --- a/src/NzbDrone.Core/Datastore/Migration/079_dedupe_tags.cs +++ b/src/NzbDrone.Core/Datastore/Migration/079_dedupe_tags.cs @@ -116,8 +116,9 @@ private void UpdateTaggedModel(IDbConnection conn, IDbTransaction tran, string t using (IDbCommand updateCmd = conn.CreateCommand()) { updateCmd.Transaction = tran; - updateCmd.CommandText = String.Format(@"UPDATE {0} SET Tags = ?", table); + updateCmd.CommandText = String.Format(@"UPDATE {0} SET Tags = ? WHERE Id = ?", table); updateCmd.AddParameter(model.Tags.ToJson()); + updateCmd.AddParameter(model.Id); updateCmd.ExecuteNonQuery(); }