Fixed: Significantly improved api performance.

This commit is contained in:
Taloth Saldono
2016-03-25 01:56:29 +01:00
parent ff6737314f
commit a2536deef0
118 changed files with 2195 additions and 1019 deletions
@@ -1,9 +1,7 @@
using System.Collections.Generic;
using FluentValidation;
using NzbDrone.Api.Mapping;
using NzbDrone.Core.RemotePathMappings;
using NzbDrone.Core.Validation.Paths;
using Omu.ValueInjecter;
namespace NzbDrone.Api.RemotePathMappings
{
@@ -39,17 +37,19 @@ namespace NzbDrone.Api.RemotePathMappings
private RemotePathMappingResource GetMappingById(int id)
{
return _remotePathMappingService.Get(id).InjectTo<RemotePathMappingResource>();
return _remotePathMappingService.Get(id).ToResource();
}
private int CreateMapping(RemotePathMappingResource rootFolderResource)
private int CreateMapping(RemotePathMappingResource resource)
{
return GetNewId<RemotePathMapping>(_remotePathMappingService.Add, rootFolderResource);
var model = resource.ToModel();
return _remotePathMappingService.Add(model).Id;
}
private List<RemotePathMappingResource> GetMappings()
{
return ToListResource(_remotePathMappingService.All);
return _remotePathMappingService.All().ToResource();
}
private void DeleteMapping(int id)
@@ -59,9 +59,7 @@ namespace NzbDrone.Api.RemotePathMappings
private void UpdateMapping(RemotePathMappingResource resource)
{
var mapping = _remotePathMappingService.Get(resource.Id);
mapping.InjectFrom(resource);
var mapping = resource.ToModel();
_remotePathMappingService.Update(mapping);
}
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Api.REST;
using NzbDrone.Core.RemotePathMappings;
namespace NzbDrone.Api.RemotePathMappings
{
@@ -9,4 +12,40 @@ namespace NzbDrone.Api.RemotePathMappings
public string RemotePath { get; set; }
public string LocalPath { get; set; }
}
public static class RemotePathMappingResourceMapper
{
public static RemotePathMappingResource ToResource(this RemotePathMapping model)
{
if (model == null) return null;
return new RemotePathMappingResource
{
Id = model.Id,
Host = model.Host,
RemotePath = model.RemotePath,
LocalPath = model.LocalPath
};
}
public static RemotePathMapping ToModel(this RemotePathMappingResource resource)
{
if (resource == null) return null;
return new RemotePathMapping
{
Id = resource.Id,
Host = resource.Host,
RemotePath = resource.RemotePath,
LocalPath = resource.LocalPath
};
}
public static List<RemotePathMappingResource> ToResource(this IEnumerable<RemotePathMapping> models)
{
return models.Select(ToResource).ToList();
}
}
}