1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-27 22:57:09 -04:00

Swap to dapper and system.text.json for database backend

This commit is contained in:
ta264
2019-12-15 15:04:42 +00:00
parent 7b17c3e36c
commit d2065bfa1b
155 changed files with 2333 additions and 2340 deletions
@@ -7,6 +7,10 @@ namespace NzbDrone.Core.CustomFormats
{
public class CustomFormat : ModelBase, IEquatable<CustomFormat>
{
public string Name { get; set; }
public List<FormatTag> FormatTags { get; set; }
public CustomFormat()
{
@@ -18,9 +22,7 @@ namespace NzbDrone.Core.CustomFormats
FormatTags = tags.Select(t => new FormatTag(t)).ToList();
}
public string Name { get; set; }
public List<FormatTag> FormatTags { get; set; }
public static implicit operator CustomFormatDefinition(CustomFormat format) => new CustomFormatDefinition { Id = format.Id, Name = format.Name, FormatTags = format.FormatTags };
public override string ToString()
{
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.CustomFormats
{
public class CustomFormatDefinition : ModelBase
{
public string Name { get; set; }
public List<FormatTag> FormatTags { get; set; }
public static implicit operator CustomFormat(CustomFormatDefinition def) => new CustomFormat { Id = def.Id, Name = def.Name, FormatTags = def.FormatTags };
}
}
@@ -3,12 +3,12 @@ using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.CustomFormats
{
public interface ICustomFormatRepository : IBasicRepository<CustomFormat>
public interface ICustomFormatRepository : IBasicRepository<CustomFormatDefinition>
{
}
public class CustomFormatRepository : BasicRepository<CustomFormat>, ICustomFormatRepository
public class CustomFormatRepository : BasicRepository<CustomFormatDefinition>, ICustomFormatRepository
{
public CustomFormatRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
@@ -7,9 +7,7 @@ using NzbDrone.Common.Composition;
using NzbDrone.Core.Blacklisting;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.History;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Profiles;
namespace NzbDrone.Core.CustomFormats
@@ -23,8 +21,7 @@ namespace NzbDrone.Core.CustomFormats
void Delete(int id);
}
public class CustomFormatService : ICustomFormatService, IHandle<ApplicationStartedEvent>
public class CustomFormatService : ICustomFormatService
{
private readonly ICustomFormatRepository _formatRepository;
private IProfileService _profileService;
@@ -58,6 +55,9 @@ namespace NzbDrone.Core.CustomFormats
_cache = cacheManager.GetCache<Dictionary<int, CustomFormat>>(typeof(CustomFormat), "formats");
_historyService = historyService;
_logger = logger;
// Fill up the cache for subsequent DB lookups
All();
}
public void Update(CustomFormat customFormat)
@@ -144,7 +144,7 @@ namespace NzbDrone.Core.CustomFormats
{
return _cache.Get("all", () =>
{
var all = _formatRepository.All().ToDictionary(m => m.Id);
var all = _formatRepository.All().Select(x => (CustomFormat)x).ToDictionary(m => m.Id);
AllCustomFormats = all;
return all;
});
@@ -194,11 +194,5 @@ namespace NzbDrone.Core.CustomFormats
};
}
}
public void Handle(ApplicationStartedEvent message)
{
// Fillup cache for DataMapper.
All();
}
}
}