Episode activity goes through History now

Do not report exceptions on linux (culture is null and fails)
This commit is contained in:
Mark McDowall 2013-10-06 11:06:39 -07:00
parent 7d2c6339bc
commit 27511769ae
12 changed files with 48 additions and 109 deletions

View File

@ -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<HistoryResource>
{
private readonly IHistoryService _historyService;
public EpisodeActivityModule(IHistoryService historyService)
: base("episodes/activity")
{
_historyService = historyService;
GetResourceAll = GetActivity;
}
private List<HistoryResource> GetActivity()
{
var episodeId = (int?)Request.Query.EpisodeId;
if (episodeId == null)
{
throw new BadRequestException("episodeId is missing");
}
return ToListResource(() => _historyService.ByEpisode(episodeId.Value));
}
}
}

View File

@ -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<HistoryResource> GetHistory(PagingResource<HistoryResource> pagingResource)
{
var episodeId = Request.Query.EpisodeId;
var pagingSpec = new PagingSpec<Core.History.History>
{
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);
}
}

View File

@ -91,7 +91,6 @@
<Compile Include="EpisodeFiles\EpisodeFileResource.cs" />
<Compile Include="Directories\DirectoryLookupService.cs" />
<Compile Include="Directories\DirectoryModule.cs" />
<Compile Include="Episodes\EpisodeActivityModule.cs" />
<Compile Include="Episodes\EpisodeModule.cs" />
<Compile Include="Episodes\EpisodeResource.cs" />
<Compile Include="Extensions\Pipelines\CacheHeaderPipeline.cs" />

View File

@ -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);

View File

@ -201,7 +201,6 @@ namespace NzbDrone.Core.Datastore
.Execute();
}
public virtual PagingSpec<TModel> GetPaged(PagingSpec<TModel> pagingSpec)
{
var pagingQuery = Query.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())

View File

@ -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<TModel> Records { get; set; }
public Expression<Func<TModel, bool>> FilterExpression { get; set; }
}
public enum SortDirection

View File

@ -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<History>
{
void Trim();
List<QualityModel> GetEpisodeHistory(int episodeId);
List<History> ByEpisode(int episodeId);
List<QualityModel> GetBestQualityInHistory(int episodeId);
}
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
@ -31,32 +31,29 @@ namespace NzbDrone.Core.History
Delete(c=> c.Date < cutoff);
}
public List<QualityModel> GetEpisodeHistory(int episodeId)
public List<QualityModel> GetBestQualityInHistory(int episodeId)
{
var history = Query.Where(c => c.EpisodeId == episodeId);
return history.Select(h => h.Quality).ToList();
}
public List<History> ByEpisode(int episodeId)
{
return Query.Where(h => h.EpisodeId == episodeId).ToList();
}
public override PagingSpec<History> GetPaged(PagingSpec<History> pagingSpec)
{
var pagingQuery = Query.Join<History, Series>(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id)
.Join<History, Episode>(JoinType.Inner, h => h.Episode, (h, e) => h.EpisodeId == e.Id)
.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();
pagingSpec.Records = GetPagedQuery(pagingSpec).ToList();
pagingSpec.TotalRecords = GetPagedQuery(pagingSpec).GetRowCount();
return pagingSpec;
}
private SortBuilder<History> GetPagedQuery(PagingSpec<History> pagingSpec)
{
return Query.Join<History, Series>(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id)
.Join<History, Episode>(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);
}
}
}

View File

@ -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<History> Paged(PagingSpec<History> pagingSpec);
List<History> ByEpisode(int episodeId);
}
public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>, IHandle<EpisodeImportedEvent>
@ -41,11 +41,6 @@ namespace NzbDrone.Core.History
return _historyRepository.GetPaged(pagingSpec);
}
public List<History> 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)

View File

@ -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);
}
});
});

View File

@ -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);
},

View File

@ -1,9 +0,0 @@
'use strict';
define(
[
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
});
});

View File

@ -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) {