Fixed: History grid loads faster (lazy loaded)

This commit is contained in:
Mark McDowall
2012-07-27 23:37:47 -07:00
parent 69a19b14c8
commit d44c07b27b
23 changed files with 245 additions and 39 deletions
+26
View File
@@ -0,0 +1,26 @@
using System;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using PetaPoco;
namespace NzbDrone.Core.Model
{
public class HistoryQueryModel
{
public int HistoryId { get; set; }
public int EpisodeId { get; set; }
public int SeriesId { get; set; }
public string NzbTitle { get; set; }
public QualityTypes Quality { get; set; }
public DateTime Date { get; set; }
public bool IsProper { get; set; }
public string Indexer { get; set; }
public string NzbInfoUrl { get; set; }
public string EpisodeTitle { get; set; }
public int SeasonNumber { get; set; }
public int EpisodeNumber { get; set; }
public string EpisodeOverview { get; set; }
public string SeriesTitle { get; set; }public int Id { get; set; }
}
}
+5
View File
@@ -123,6 +123,10 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="DataTables.Mvc.Core, Version=0.1.0.85, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\DataTables.Mvc.Core.0.1.0.85\lib\DataTables.Mvc.Core.dll</HintPath>
</Reference>
<Reference Include="DeskMetrics.NET">
<HintPath>..\Libraries\DeskMetrics\DeskMetrics.NET.dll</HintPath>
</Reference>
@@ -251,6 +255,7 @@
<Compile Include="Jobs\RefreshEpsiodeMetadata.cs" />
<Compile Include="Jobs\PastWeekBacklogSearchJob.cs" />
<Compile Include="Jobs\SearchHistoryCleanupJob.cs" />
<Compile Include="Model\HistoryQueryModel.cs" />
<Compile Include="Model\DownloadClientType.cs" />
<Compile Include="Instrumentation\LogDbContext.cs" />
<Compile Include="Instrumentation\LogProvider.cs" />
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DataTables.Mvc.Core.Helpers;
using DataTables.Mvc.Core.Models;
using Ninject;
using NLog;
using NzbDrone.Core.Model;
@@ -77,5 +79,42 @@ namespace NzbDrone.Core.Providers
{
_database.Delete<History>(historyId);
}
public virtual Page<HistoryQueryModel> GetPagedItems(DataTablesPageRequest pageRequest)
{
var query = Sql.Builder
.Select(@"History.*, Series.Title as SeriesTitle, Episodes.Title as EpisodeTitle,
Episodes.SeasonNumber as SeasonNumber, Episodes.EpisodeNumber as EpisodeNumber,
Episodes.Overview as EpisodeOverview")
.From("History")
.InnerJoin("Series")
.On("History.SeriesId = Series.SeriesId")
.InnerJoin("Episodes")
.On("History.EpisodeId = Episodes.EpisodeId");
var startPage = (pageRequest.DisplayLength == 0) ? 1 : pageRequest.DisplayStart / pageRequest.DisplayLength + 1;
if (!string.IsNullOrEmpty(pageRequest.Search))
{
var whereClause = string.Join(" OR ", SqlBuilderHelper.GetSearchClause(pageRequest));
if (!string.IsNullOrEmpty(whereClause))
query.Append("WHERE " + whereClause, "%" + pageRequest.Search + "%");
}
var orderBy = string.Join(",", SqlBuilderHelper.GetOrderByClause(pageRequest));
if (!string.IsNullOrEmpty(orderBy))
{
query.Append("ORDER BY " + orderBy);
}
return _database.Page<HistoryQueryModel>(startPage, pageRequest.DisplayLength, query);
}
public virtual long Count()
{
return _database.Single<long>(@"SELECT COUNT(*) from History");
}
}
}
+1
View File
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DataTables.Mvc.Core" version="0.1.0.85" />
<package id="DotNetZip" version="1.9.1.8" />
<package id="EntityFramework" version="4.3.0" />
<package id="EntityFramework.SqlServerCompact" version="4.1.8482.2" />