mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-03-09 15:00:03 -04:00
Compare commits
1 Commits
api-docs
...
improve-sc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b1fa88c63 |
@@ -46,6 +46,10 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
|
||||
|
||||
_provider2 = new Mock<ISceneMappingProvider>();
|
||||
_provider2.Setup(s => s.GetSceneMappings()).Returns(_fakeMappings);
|
||||
|
||||
Mocker.GetMock<ISceneMappingRepository>()
|
||||
.Setup(c => c.GetAllByType(It.IsAny<string>()))
|
||||
.Returns(new List<SceneMapping>());
|
||||
}
|
||||
|
||||
private void GivenProviders(IEnumerable<Mock<ISceneMappingProvider>> providers)
|
||||
@@ -375,15 +379,15 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
|
||||
private void AssertNoUpdate()
|
||||
{
|
||||
_provider1.Verify(c => c.GetSceneMappings(), Times.Once());
|
||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.Clear(It.IsAny<string>()), Times.Never());
|
||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.InsertMany(_fakeMappings), Times.Never());
|
||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.InsertMany(It.IsAny<IList<SceneMapping>>()), Times.Never());
|
||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.UpdateMany(It.IsAny<IList<SceneMapping>>()), Times.Never());
|
||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.DeleteMany(It.IsAny<List<SceneMapping>>()), Times.Never());
|
||||
}
|
||||
|
||||
private void AssertMappingUpdated()
|
||||
{
|
||||
_provider1.Verify(c => c.GetSceneMappings(), Times.Once());
|
||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.Clear(It.IsAny<string>()), Times.Once());
|
||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.InsertMany(_fakeMappings), Times.Once());
|
||||
Mocker.GetMock<ISceneMappingRepository>().Verify(c => c.InsertMany(It.IsAny<IList<SceneMapping>>()), Times.Once());
|
||||
|
||||
foreach (var sceneMapping in _fakeMappings)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
||||
{
|
||||
public class SceneMapping : ModelBase
|
||||
{
|
||||
public string MappingId { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string ParseTerm { get; set; }
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
||||
public interface ISceneMappingRepository : IBasicRepository<SceneMapping>
|
||||
{
|
||||
List<SceneMapping> FindByTvdbid(int tvdbId);
|
||||
void Clear(string type);
|
||||
List<SceneMapping> GetAllByType(string type);
|
||||
}
|
||||
|
||||
public class SceneMappingRepository : BasicRepository<SceneMapping>, ISceneMappingRepository
|
||||
@@ -22,9 +22,9 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
||||
return Query(x => x.TvdbId == tvdbId);
|
||||
}
|
||||
|
||||
public void Clear(string type)
|
||||
public List<SceneMapping> GetAllByType(string type)
|
||||
{
|
||||
Delete(s => s.Type == type);
|
||||
return Query(x => x.Type == type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
||||
|
||||
if (mappings.Any())
|
||||
{
|
||||
_repository.Clear(sceneMappingProvider.GetType().Name);
|
||||
var providerType = sceneMappingProvider.GetType().Name;
|
||||
|
||||
mappings.RemoveAll(sceneMapping =>
|
||||
{
|
||||
@@ -160,10 +160,45 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
||||
foreach (var sceneMapping in mappings)
|
||||
{
|
||||
sceneMapping.ParseTerm = sceneMapping.Title.CleanSeriesTitle();
|
||||
sceneMapping.Type = sceneMappingProvider.GetType().Name;
|
||||
sceneMapping.Type = providerType;
|
||||
}
|
||||
|
||||
_repository.InsertMany(mappings.ToList());
|
||||
var existing = _repository.GetAllByType(providerType);
|
||||
var existingByMappingId = new Dictionary<string, SceneMapping>();
|
||||
|
||||
foreach (var e in existing)
|
||||
{
|
||||
existingByMappingId[e.MappingId ?? $"{e.Id}"] = e;
|
||||
}
|
||||
|
||||
var toInsert = new List<SceneMapping>();
|
||||
var toUpdate = new List<SceneMapping>();
|
||||
|
||||
foreach (var mapping in mappings)
|
||||
{
|
||||
if (mapping.MappingId.IsNullOrWhiteSpace())
|
||||
{
|
||||
_logger.Warn("Scene mapping with missing MappingId found for: {0} {1}, skipping", mapping.TvdbId, mapping.Title);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (existingByMappingId.TryGetValue(mapping.MappingId, out var existingMapping))
|
||||
{
|
||||
mapping.Id = existingMapping.Id;
|
||||
toUpdate.Add(mapping);
|
||||
existingByMappingId.Remove(mapping.MappingId);
|
||||
}
|
||||
else
|
||||
{
|
||||
toInsert.Add(mapping);
|
||||
}
|
||||
}
|
||||
|
||||
var toDelete = existingByMappingId.Values.ToList();
|
||||
|
||||
_repository.DeleteMany(toDelete);
|
||||
_repository.UpdateMany(toUpdate);
|
||||
_repository.InsertMany(toInsert);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace NzbDrone.Core.DataAugmentation.Xem
|
||||
|
||||
result.Add(new SceneMapping
|
||||
{
|
||||
MappingId = $"x-{series.Key}_S{seasonNumber}_{n.Key.Replace(' ', '_')}",
|
||||
Title = n.Key,
|
||||
SearchTerm = n.Key,
|
||||
SceneSeasonNumber = seasonNumber,
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(230)]
|
||||
public class add_mapping_id_to_scene_mappings : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("SceneMappings")
|
||||
.AddColumn("MappingId").AsString().Nullable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7518,8 +7518,7 @@
|
||||
"notQualityUpgrade",
|
||||
"notRevisionUpgrade",
|
||||
"notCustomFormatUpgrade",
|
||||
"notCustomFormatUpgradeAfterRename",
|
||||
"multiSeason"
|
||||
"notCustomFormatUpgradeAfterRename"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user