From 27511769aefe72c1ad9fe66b19bd3537799a08ad Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 6 Oct 2013 11:06:39 -0700 Subject: [PATCH] Episode activity goes through History now Do not report exceptions on linux (culture is null and fails) --- .../Episodes/EpisodeActivityModule.cs | 39 ------------------- src/NzbDrone.Api/History/HistoryModule.cs | 13 ++++++- src/NzbDrone.Api/NzbDrone.Api.csproj | 1 - .../Instrumentation/ExceptronTarget.cs | 1 + .../Datastore/BasicRepository.cs | 1 - src/NzbDrone.Core/Datastore/PagingSpec.cs | 5 ++- .../History/HistoryRepository.cs | 25 ++++++------ src/NzbDrone.Core/History/HistoryService.cs | 9 +---- .../Activity/EpisodeActivityCollection.js | 28 ------------- .../Episode/Activity/EpisodeActivityLayout.js | 6 +-- .../Episode/Activity/EpisodeActivityModel.js | 9 ----- src/UI/History/HistoryCollection.js | 12 +++++- 12 files changed, 44 insertions(+), 105 deletions(-) delete mode 100644 src/NzbDrone.Api/Episodes/EpisodeActivityModule.cs delete mode 100644 src/UI/Episode/Activity/EpisodeActivityCollection.js delete mode 100644 src/UI/Episode/Activity/EpisodeActivityModel.js diff --git a/src/NzbDrone.Api/Episodes/EpisodeActivityModule.cs b/src/NzbDrone.Api/Episodes/EpisodeActivityModule.cs deleted file mode 100644 index 35eae7fcc..000000000 --- a/src/NzbDrone.Api/Episodes/EpisodeActivityModule.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using NzbDrone.Api.History; -using NzbDrone.Api.Mapping; -using NzbDrone.Api.REST; -using NzbDrone.Core.Datastore.Events; -using NzbDrone.Core.Download; -using NzbDrone.Core.History; -using NzbDrone.Core.MediaFiles.Events; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Api.Episodes -{ - public class EpisodeActivityModule : NzbDroneRestModule - - { - private readonly IHistoryService _historyService; - - public EpisodeActivityModule(IHistoryService historyService) - : base("episodes/activity") - { - _historyService = historyService; - - GetResourceAll = GetActivity; - } - - private List GetActivity() - { - var episodeId = (int?)Request.Query.EpisodeId; - - if (episodeId == null) - { - throw new BadRequestException("episodeId is missing"); - } - - return ToListResource(() => _historyService.ByEpisode(episodeId.Value)); - } - } -} \ No newline at end of file diff --git a/src/NzbDrone.Api/History/HistoryModule.cs b/src/NzbDrone.Api/History/HistoryModule.cs index 9069f2930..85b3f6135 100644 --- a/src/NzbDrone.Api/History/HistoryModule.cs +++ b/src/NzbDrone.Api/History/HistoryModule.cs @@ -1,4 +1,7 @@ -using NzbDrone.Core.Datastore; +using System; +using System.Collections.Generic; +using NzbDrone.Api.Mapping; +using NzbDrone.Core.Datastore; using NzbDrone.Core.History; namespace NzbDrone.Api.History @@ -15,6 +18,8 @@ namespace NzbDrone.Api.History private PagingResource GetHistory(PagingResource pagingResource) { + var episodeId = Request.Query.EpisodeId; + var pagingSpec = new PagingSpec { Page = pagingResource.Page, @@ -23,6 +28,12 @@ namespace NzbDrone.Api.History SortDirection = pagingResource.SortDirection }; + if (episodeId.HasValue) + { + int i = (int)episodeId; + pagingSpec.FilterExpression = h => h.EpisodeId == i; + } + return ApplyToPage(_historyService.Paged, pagingSpec); } } diff --git a/src/NzbDrone.Api/NzbDrone.Api.csproj b/src/NzbDrone.Api/NzbDrone.Api.csproj index 19d51cea7..7b885fe48 100644 --- a/src/NzbDrone.Api/NzbDrone.Api.csproj +++ b/src/NzbDrone.Api/NzbDrone.Api.csproj @@ -91,7 +91,6 @@ - diff --git a/src/NzbDrone.Common/Instrumentation/ExceptronTarget.cs b/src/NzbDrone.Common/Instrumentation/ExceptronTarget.cs index f824a5ac4..32c2c4238 100644 --- a/src/NzbDrone.Common/Instrumentation/ExceptronTarget.cs +++ b/src/NzbDrone.Common/Instrumentation/ExceptronTarget.cs @@ -47,6 +47,7 @@ namespace NzbDrone.Common.Instrumentation protected override void Write(LogEventInfo logEvent) { if (logEvent == null || logEvent.Exception == null) return; + if (OsInfo.IsLinux) return; InternalLogger.Trace("Sending Exception to api.exceptron.com. Process Name: {0}", Process.GetCurrentProcess().ProcessName); diff --git a/src/NzbDrone.Core/Datastore/BasicRepository.cs b/src/NzbDrone.Core/Datastore/BasicRepository.cs index 96c03e51e..f3e35930f 100644 --- a/src/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/src/NzbDrone.Core/Datastore/BasicRepository.cs @@ -201,7 +201,6 @@ namespace NzbDrone.Core.Datastore .Execute(); } - public virtual PagingSpec GetPaged(PagingSpec pagingSpec) { var pagingQuery = Query.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()) diff --git a/src/NzbDrone.Core/Datastore/PagingSpec.cs b/src/NzbDrone.Core/Datastore/PagingSpec.cs index c1b7eb8a7..37bd9776c 100644 --- a/src/NzbDrone.Core/Datastore/PagingSpec.cs +++ b/src/NzbDrone.Core/Datastore/PagingSpec.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; namespace NzbDrone.Core.Datastore { @@ -10,6 +12,7 @@ namespace NzbDrone.Core.Datastore public string SortKey { get; set; } public SortDirection SortDirection { get; set; } public List Records { get; set; } + public Expression> FilterExpression { get; set; } } public enum SortDirection diff --git a/src/NzbDrone.Core/History/HistoryRepository.cs b/src/NzbDrone.Core/History/HistoryRepository.cs index b622ac3b8..5a6cf5244 100644 --- a/src/NzbDrone.Core/History/HistoryRepository.cs +++ b/src/NzbDrone.Core/History/HistoryRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using Marr.Data.QGen; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging.Events; @@ -11,8 +12,7 @@ namespace NzbDrone.Core.History public interface IHistoryRepository : IBasicRepository { void Trim(); - List GetEpisodeHistory(int episodeId); - List ByEpisode(int episodeId); + List GetBestQualityInHistory(int episodeId); } public class HistoryRepository : BasicRepository, IHistoryRepository @@ -31,32 +31,29 @@ namespace NzbDrone.Core.History Delete(c=> c.Date < cutoff); } - public List GetEpisodeHistory(int episodeId) + public List GetBestQualityInHistory(int episodeId) { var history = Query.Where(c => c.EpisodeId == episodeId); return history.Select(h => h.Quality).ToList(); } - public List ByEpisode(int episodeId) + public override PagingSpec GetPaged(PagingSpec pagingSpec) { - return Query.Where(h => h.EpisodeId == episodeId).ToList(); + pagingSpec.Records = GetPagedQuery(pagingSpec).ToList(); + pagingSpec.TotalRecords = GetPagedQuery(pagingSpec).GetRowCount(); + + return pagingSpec; } - public override PagingSpec GetPaged(PagingSpec pagingSpec) + private SortBuilder GetPagedQuery(PagingSpec pagingSpec) { - var pagingQuery = Query.Join(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id) + return Query.Join(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id) .Join(JoinType.Inner, h => h.Episode, (h, e) => h.EpisodeId == e.Id) + .Where(pagingSpec.FilterExpression) .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()) .Skip(pagingSpec.PagingOffset()) .Take(pagingSpec.PageSize); - - pagingSpec.Records = pagingQuery.ToList(); - - //TODO: Use the same query for count and records - pagingSpec.TotalRecords = Count(); - - return pagingSpec; } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index 5a32aae21..ed09ae94e 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using NLog; using NzbDrone.Core.Datastore; using NzbDrone.Core.Download; @@ -17,7 +18,6 @@ namespace NzbDrone.Core.History void Trim(); QualityModel GetBestQualityInHistory(int episodeId); PagingSpec Paged(PagingSpec pagingSpec); - List ByEpisode(int episodeId); } public class HistoryService : IHistoryService, IHandle, IHandle @@ -41,11 +41,6 @@ namespace NzbDrone.Core.History return _historyRepository.GetPaged(pagingSpec); } - public List ByEpisode(int episodeId) - { - return _historyRepository.ByEpisode(episodeId); - } - public void Purge() { _historyRepository.Purge(); @@ -58,7 +53,7 @@ namespace NzbDrone.Core.History public virtual QualityModel GetBestQualityInHistory(int episodeId) { - return _historyRepository.GetEpisodeHistory(episodeId).OrderByDescending(q => q).FirstOrDefault(); + return _historyRepository.GetBestQualityInHistory(episodeId).OrderByDescending(q => q).FirstOrDefault(); } public void Handle(EpisodeGrabbedEvent message) diff --git a/src/UI/Episode/Activity/EpisodeActivityCollection.js b/src/UI/Episode/Activity/EpisodeActivityCollection.js deleted file mode 100644 index 3ae1693b8..000000000 --- a/src/UI/Episode/Activity/EpisodeActivityCollection.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; -define( - [ - 'backbone', - 'Episode/Activity/EpisodeActivityModel' - ], function (Backbone, EpisodeActivityModel) { - return Backbone.Collection.extend({ - url : window.NzbDrone.ApiRoot + '/episodes/activity', - model: EpisodeActivityModel, - - originalFetch: Backbone.Collection.prototype.fetch, - - initialize: function (options) { - if (!options.episodeId) { - throw 'episodeId is required'; - } - - this.episodeId = options.episodeId; - }, - - fetch: function (options) { - options = options || {}; - options.data = { episodeId: this.episodeId }; - - return this.originalFetch.call(this, options); - } - }); - }); diff --git a/src/UI/Episode/Activity/EpisodeActivityLayout.js b/src/UI/Episode/Activity/EpisodeActivityLayout.js index 50c3f08ba..646a560dd 100644 --- a/src/UI/Episode/Activity/EpisodeActivityLayout.js +++ b/src/UI/Episode/Activity/EpisodeActivityLayout.js @@ -4,12 +4,12 @@ define( 'app', 'marionette', 'backgrid', - 'Episode/Activity/EpisodeActivityCollection', + 'History/HistoryCollection', 'Cells/EventTypeCell', 'Cells/QualityCell', 'Cells/RelativeDateCell', 'Shared/LoadingView' - ], function (App, Marionette, Backgrid, EpisodeActivityCollection, EventTypeCell, QualityCell, RelativeDateCell, LoadingView) { + ], function (App, Marionette, Backgrid, HistoryCollection, EventTypeCell, QualityCell, RelativeDateCell, LoadingView) { return Marionette.Layout.extend({ template: 'Episode/Activity/EpisodeActivityLayoutTemplate', @@ -47,7 +47,7 @@ define( this.model = options.model; this.series = options.series; - this.collection = new EpisodeActivityCollection({ episodeId: this.model.id }); + this.collection = new HistoryCollection({ episodeId: this.model.id }); this.collection.fetch(); this.listenTo(this.collection, 'sync', this._showTable); }, diff --git a/src/UI/Episode/Activity/EpisodeActivityModel.js b/src/UI/Episode/Activity/EpisodeActivityModel.js deleted file mode 100644 index 808c9c77c..000000000 --- a/src/UI/Episode/Activity/EpisodeActivityModel.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; -define( - [ - 'backbone' - ], function (Backbone) { - return Backbone.Model.extend({ - - }); - }); diff --git a/src/UI/History/HistoryCollection.js b/src/UI/History/HistoryCollection.js index 821dd086b..5341c6507 100644 --- a/src/UI/History/HistoryCollection.js +++ b/src/UI/History/HistoryCollection.js @@ -26,8 +26,18 @@ define( } }, + initialize: function (options) { + delete this.queryParams.episodeId; + + if (options) { + if (options.episodeId) { + this.queryParams.episodeId = options.episodeId; + } + } + }, + parseState: function (resp) { - return {totalRecords: resp.totalRecords}; + return { totalRecords: resp.totalRecords }; }, parseRecords: function (resp) {