From 1454f158f5c54ff1a89acc41c519b29ca69427e8 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 6 Sep 2013 17:45:13 -0700 Subject: [PATCH] Added caching to SAB --- .../Scene/SceneMappingService.cs | 1 - .../Download/Clients/Sabnzbd/SabnzbdClient.cs | 44 ++++++++++++------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs index 5e6c2a6af..e857f5373 100644 --- a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs +++ b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs @@ -18,7 +18,6 @@ public class SceneMappingService : ISceneMappingService, IHandleAsync, IExecute { - private readonly ISceneMappingRepository _repository; private readonly ISceneMappingProxy _sceneMappingProxy; private readonly Logger _logger; diff --git a/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs b/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs index 281096945..276ee5a5a 100644 --- a/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs +++ b/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Linq; using NLog; using NzbDrone.Common; +using NzbDrone.Common.Cache; using NzbDrone.Core.Configuration; using NzbDrone.Core.Parser.Model; using RestSharp; @@ -53,12 +54,14 @@ public class SabnzbdClient : IDownloadClient { private readonly IConfigService _configService; private readonly IHttpProvider _httpProvider; + private readonly ICached> _queueCache; private readonly Logger _logger; - public SabnzbdClient(IConfigService configService, IHttpProvider httpProvider, Logger logger) + public SabnzbdClient(IConfigService configService, IHttpProvider httpProvider, ICacheManger cacheManger, Logger logger) { _configService = configService; _httpProvider = httpProvider; + _queueCache = cacheManger.GetCache>(GetType(), "queue"); _logger = logger; } @@ -97,24 +100,31 @@ public bool IsConfigured public IEnumerable GetQueue() { - string action = String.Format("mode=queue&output=json&start={0}&limit={1}", 0, 0); - string request = GetSabRequest(action); - string response = _httpProvider.DownloadString(request); - - CheckForError(response); - - var sabQueue = JsonConvert.DeserializeObject(JObject.Parse(response).SelectToken("queue").ToString()).Items; - - foreach (var sabQueueItem in sabQueue) + return _queueCache.Get("queue", () => { - var queueItem = new QueueItem(); - queueItem.Id = sabQueueItem.Id; - queueItem.Title = sabQueueItem.Title; - queueItem.Size = sabQueueItem.Size; - queueItem.SizeLeft = sabQueueItem.Size; + string action = String.Format("mode=queue&output=json&start={0}&limit={1}", 0, 0); + string request = GetSabRequest(action); + string response = _httpProvider.DownloadString(request); - yield return queueItem; - } + CheckForError(response); + + var sabQueue = JsonConvert.DeserializeObject(JObject.Parse(response).SelectToken("queue").ToString()).Items; + + var queueItems = new List(); + + foreach (var sabQueueItem in sabQueue) + { + var queueItem = new QueueItem(); + queueItem.Id = sabQueueItem.Id; + queueItem.Title = sabQueueItem.Title; + queueItem.Size = sabQueueItem.Size; + queueItem.SizeLeft = sabQueueItem.Size; + + queueItems.Add( queueItem); + } + + return queueItems; + }, TimeSpan.FromSeconds(10)); } public virtual List GetHistory(int start = 0, int limit = 0)