Fixed: History grid loads faster (lazy loaded)

pull/2/head
Mark McDowall 12 years ago
parent 69a19b14c8
commit d44c07b27b

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

@ -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,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" />

@ -10,8 +10,8 @@ namespace NzbDrone.Web.App_Start
{
public static void Start()
{
if (!ModelBinders.Binders.ContainsKey(typeof(DataTablesParams)))
ModelBinders.Binders.Add(typeof(DataTablesParams), new DataTablesModelBinder());
if (!ModelBinders.Binders.ContainsKey(typeof(DataTablesPageRequest)))
ModelBinders.Binders.Add(typeof(DataTablesPageRequest), new DataTablesModelBinder());
}
}
}

@ -1,6 +1,9 @@
using System.Linq;
using System;
using System.Linq;
using System.Linq.Dynamic;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using DataTables.Mvc.Core.Models;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Providers;
@ -24,15 +27,46 @@ namespace NzbDrone.Web.Controllers
return View();
}
public JsonResult AjaxBinding()
//public JsonResult AjaxBinding()
//{
// var history = _historyProvider.AllItemsWithRelationships().Select(h => new HistoryModel
// {
// HistoryId = h.HistoryId,
// SeriesId = h.SeriesId,
// EpisodeNumbering = string.Format("{0}x{1:00}", h.Episode.SeasonNumber, h.Episode.EpisodeNumber),
// EpisodeTitle = h.Episode.Title,
// EpisodeOverview = h.Episode.Overview,
// SeriesTitle = h.SeriesTitle,
// SeriesTitleSorter = SortHelper.SkipArticles(h.SeriesTitle),
// NzbTitle = h.NzbTitle,
// Quality = h.Quality.ToString(),
// IsProper = h.IsProper,
// Date = h.Date.ToString(),
// DateSorter = h.Date.ToString("MM/dd/yyyy h:mm:ss tt"),
// Indexer = h.Indexer,
// EpisodeId = h.EpisodeId,
// NzbInfoUrl = h.NzbInfoUrl
// }).OrderByDescending(h => h.Date).ToList();
// return Json(new
// {
// aaData = history
// },
// JsonRequestBehavior.AllowGet);
//}
public ActionResult AjaxBinding(DataTablesPageRequest pageRequest)
{
var history = _historyProvider.AllItemsWithRelationships().Select(h => new HistoryModel
var pageResult = _historyProvider.GetPagedItems(pageRequest);
var totalItems = _historyProvider.Count();
var items = pageResult.Items.Select(h => new HistoryModel
{
HistoryId = h.HistoryId,
SeriesId = h.SeriesId,
EpisodeNumbering = string.Format("{0}x{1:00}", h.Episode.SeasonNumber, h.Episode.EpisodeNumber),
EpisodeTitle = h.Episode.Title,
EpisodeOverview = h.Episode.Overview,
EpisodeNumbering = string.Format("{0}x{1:00}", h.SeasonNumber, h.EpisodeNumber),
EpisodeTitle = h.EpisodeTitle,
EpisodeOverview = h.EpisodeOverview,
SeriesTitle = h.SeriesTitle,
SeriesTitleSorter = SortHelper.SkipArticles(h.SeriesTitle),
NzbTitle = h.NzbTitle,
@ -43,11 +77,14 @@ namespace NzbDrone.Web.Controllers
Indexer = h.Indexer,
EpisodeId = h.EpisodeId,
NzbInfoUrl = h.NzbInfoUrl
}).OrderByDescending(h => h.Date).ToList();
});
return Json(new
{
aaData = history
sEcho = pageRequest.Echo,
iTotalRecords = totalItems,
iTotalDisplayRecords = pageResult.TotalItems,
aaData = items
},
JsonRequestBehavior.AllowGet);
}

@ -52,36 +52,36 @@ namespace NzbDrone.Web.Controllers
return JsonNotificationResult.Info("Logs Cleared");
}
public ActionResult AjaxBinding(DataTablesParams dataTablesParams)
public ActionResult AjaxBinding(DataTablesPageRequest pageRequest)
{
var logs = _logProvider.GetAllLogs();
var totalCount = logs.Count();
IQueryable<Log> q = logs;
if (!string.IsNullOrEmpty(dataTablesParams.sSearch))
if (!string.IsNullOrEmpty(pageRequest.Search))
{
q = q.Where(b => b.Logger.Contains(dataTablesParams.sSearch)
|| b.Exception.Contains(dataTablesParams.sSearch)
|| b.Message.Contains(dataTablesParams.sSearch));
q = q.Where(b => b.Logger.Contains(pageRequest.Search)
|| b.Exception.Contains(pageRequest.Search)
|| b.Message.Contains(pageRequest.Search));
}
int filteredCount = q.Count();
IQueryable<Log> sorted = q;
for (int i = 0; i < dataTablesParams.iSortingCols; i++)
for (int i = 0; i < pageRequest.SortingCols; i++)
{
int sortCol = dataTablesParams.iSortCol[i];
int sortCol = pageRequest.SortCol[i];
var sortColName = sortCol == 0 ? "Time" : sortCol == 1 ? "Level" : "Logger";
var sortExpression = String.Format("{0} {1}", sortColName, dataTablesParams.sSortDir[i]);
var sortExpression = String.Format("{0} {1}", sortColName, pageRequest.SortDir[i]);
sorted = sorted.OrderBy(sortExpression);
}
IQueryable<Log> filteredAndSorted = sorted;
if (filteredCount > dataTablesParams.iDisplayLength)
if (filteredCount > pageRequest.DisplayLength)
{
filteredAndSorted = sorted.Skip(dataTablesParams.iDisplayStart).Take(dataTablesParams.iDisplayLength);
filteredAndSorted = sorted.Skip(pageRequest.DisplayStart).Take(pageRequest.DisplayLength);
}
var logModels = filteredAndSorted.ToList().Select(s => new LogModel
@ -97,7 +97,7 @@ namespace NzbDrone.Web.Controllers
return Json(new
{
sEcho = dataTablesParams.sEcho,
sEcho = pageRequest.Echo,
iTotalRecords = totalCount,
iTotalDisplayRecords = filteredCount,
aaData = logModels

@ -53,9 +53,9 @@
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="DataTables.Mvc.Core">
<HintPath>..\packages\DataTables.Mvc.0.1.0.79\lib\DataTables.Mvc.Core.dll</HintPath>
<Private>True</Private>
<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="Dynamic">
<HintPath>..\packages\DynamicQuery.1.0\lib\35\Dynamic.dll</HintPath>
@ -142,9 +142,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\TvdbLib.dll</HintPath>
</Reference>
<Reference Include="WebActivator, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="WebActivator, Version=1.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\WebActivator.1.5\lib\net40\WebActivator.dll</HintPath>
<HintPath>..\packages\WebActivator.1.5.1\lib\net40\WebActivator.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@ -363,6 +363,7 @@
<Content Include="Scripts\DataTables-1.9.0\media\js\jquery.dataTables.editable.js" />
<Content Include="Scripts\DataTables-1.9.0\media\js\jquery.dataTables.js" />
<Content Include="Scripts\DataTables-1.9.0\media\js\jquery.dataTables.min.js" />
<Content Include="Scripts\DataTables-1.9.0\media\js\jquery.dataTablesFilteringDelay.js" />
<Content Include="Scripts\DataTables-1.9.0\media\js\jquery.jeditable.js" />
<Content Include="Scripts\jquery-1.7.1-vsdoc.js" />
<Content Include="Scripts\jquery-1.7.1.min.js" />

@ -0,0 +1,33 @@
$.fn.dataTableExt.oApi.fnSetFilteringDelay = function (oSettings, iDelay) {
/*
* Inputs: object:oSettings - dataTables settings object - automatically given
* integer:iDelay - delay in milliseconds
* Usage: $('#example').dataTable().fnSetFilteringDelay(250);
* Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
* License: GPL v2 or BSD 3 point style
* Contact: zygimantas.berziunas /AT\ hotmail.com
*/
var _that = this,
iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
this.each(function (i) {
$.fn.dataTableExt.iApiIndex = i;
var oTimerId = null,
sPreviousSearch = null,
anControl = $('input', _that.fnSettings().aanFeatures.f);
anControl.unbind('keyup').bind('keyup', function () {
if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
window.clearTimeout(oTimerId);
sPreviousSearch = anControl.val();
oTimerId = window.setTimeout(function () {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter(anControl.val());
}, iDelay);
}
});
return this;
});
return this;
};

@ -46,7 +46,7 @@
oTable = $('#historyGrid').dataTable({
"sAjaxSource": "History/AjaxBinding",
"bServerSide": false,
"bServerSide": true,
"bProcessing": true,
"bShowAll": false,
"bPaginate": true,
@ -59,7 +59,7 @@
"sPaginationType": "four_button",
"aoColumns": [
{
sWidth: '20px', "bSortable": false, "mDataProp": function (source, type, val) {
sName: 'Icon', sWidth: '20px', "bSortable": false, "bSearchable": false, "mDataProp": function (source, type, val) {
// 'display' and 'filter' use the image
if (type === 'display' || type === 'filter') {
if (source['Indexer'].indexOf("Newznab") === 0)
@ -71,7 +71,8 @@
return source["Indexer"];
}
}, //Image
{ sWidth: 'auto', "mDataProp": function (source, type, val) {
{
sName: 'Series.Title', sWidth: 'auto', "mDataProp": function (source, type, val) {
// 'display' and 'filter' use our fancy naming
if (type === 'display' || type === 'filter') {
return "<a href='/Series/Details?seriesId=" + source["SeriesId"] + "'>" + source["SeriesTitle"] + "</a>";
@ -80,10 +81,10 @@
return source["SeriesTitleSorter"];
}
}, //Series Title
{ sWidth: '80px', "mDataProp": "EpisodeNumbering", "bSortable": false }, //EpisodeNumbering
{ sWidth: 'auto', "mDataProp": "EpisodeTitle", "bSortable": false }, //Episode Title
{ sWidth: '70px', "mDataProp": "Quality", "bSortable": false }, //Quality
{ sWidth: '150px', "mDataProp": function (source, type, val) {
{ sName: 'EpisodeNumbering', sWidth: '80px', "mDataProp": "EpisodeNumbering", "bSortable": false, "bSearchable": false }, //EpisodeNumbering
{ sName: 'Episodes.Title', sWidth: 'auto', "mDataProp": "EpisodeTitle", "bSortable": false }, //Episode Title
{ sName: 'Quality', sWidth: '70px', "mDataProp": "Quality", "bSortable": false, "bSearchable": false }, //Quality
{ sName: 'Date', sWidth: '150px', "bSearchable": false, "mDataProp": function (source, type, val) {
// 'display' and 'filter' use our fancy naming
if (type === 'display' || type === 'filter') {
return source["Date"];
@ -92,7 +93,7 @@
return source["DateSorter"];
}
}, //Date
{ sWidth: '40px', "mDataProp": "HistoryId", "bSortable": false, "fnRender": function (row) {
{ sName: 'Actions', sWidth: '40px', "mDataProp": "HistoryId", "bSortable": false, "bSearchable": false, "fnRender": function (row) {
var deleteImage = "<img src=\"../../Content/Images/close.png\" alt=\"Delete\" title=\"Delete from History\" class=\"gridAction\" onclick=\"deleteHistory(this.parentNode.parentNode, " + row.aData["HistoryId"] + ")\">";
var redownloadImage = "<img src=\"../../Content/Images/redownload.png\" alt=\"Redownload\" title=\Redownload Episode\" class=\"gridAction\" onclick=\"redownloadHistory(this.parentNode.parentNode, " + row.aData["HistoryId"] + ", " + row.aData["EpisodeId"] + ")\">";
@ -100,9 +101,10 @@
}
}, //Actions
{
sWidth: 'auto',
sName: 'Details', sWidth: 'auto',
"mDataProp": "Details",
"bSortable": false,
"bSearchable": false,
"bVisible": false,
"fnRender": function(row) {
var result = "<b>Overview: </b>" + row.aData["EpisodeOverview"] + "<br/>" +
@ -118,7 +120,7 @@
} //Details
],
"aaSorting": [[5, 'desc']]
});
}).fnSetFilteringDelay(500);
});
function deleteHistory(row, historyId) {

@ -44,7 +44,8 @@
@Html.IncludeScript("DataTables-1.9.0/media/js/jquery.dataTables.min.js")
@Html.IncludeScript("DataTables-1.9.0/media/js/jquery.dataTables.reloadAjax.js")
@Html.IncludeScript("DataTables-1.9.0/media/js/jquery.dataTables.editable.js")
@Html.IncludeScript("DataTables-1.9.0/media/js/jquery.jeditable.js")
@Html.IncludeScript("DataTables-1.9.0/media/js/jquery.jeditable.js")s
@Html.IncludeScript("DataTables-1.9.0/media/js/jquery.dataTablesFilteringDelay.js")
@Html.IncludeScript("jquery.dataTables.4button.pagination.js")
@RenderSection("Scripts", required: false)
</body>

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DataTables.Mvc" version="0.1.0.79" />
<package id="DataTables.Mvc" version="0.1.0.85" />
<package id="DataTables.Mvc.Core" version="0.1.0.85" />
<package id="DynamicQuery" version="1.0" />
<package id="EntityFramework" version="4.3.0" />
<package id="EntityFramework.SqlServerCompact" version="4.1.8482.2" />
@ -27,5 +28,5 @@
<package id="SignalR.Js" version="0.4.0.1" />
<package id="SignalR.Server" version="0.4.0.0" />
<package id="SqlServerCompact" version="4.0.8482.1" />
<package id="WebActivator" version="1.5" />
<package id="WebActivator" version="1.5.1" />
</packages>

@ -0,0 +1,19 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>

@ -0,0 +1,19 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
</ProjectConfiguration>

@ -0,0 +1,17 @@
using DataTables.Mvc.Core.Helpers;
using DataTables.Mvc.Core.Models;
using System.Web.Mvc;
[assembly: WebActivator.PreApplicationStartMethod(typeof($rootnamespace$.App_Start.DataTablesModelBinderActivator), "Start")]
namespace $rootnamespace$.App_Start
{
public static class DataTablesModelBinderActivator
{
public static void Start()
{
if (!ModelBinders.Binders.ContainsKey(typeof(DataTablesPageRequest)))
ModelBinders.Binders.Add(typeof(DataTablesPageRequest), new DataTablesModelBinder());
}
}
}

@ -0,0 +1,5 @@
param($installPath, $toolsPath, $package, $project)
$path = [System.IO.Path]
$appstart = $path::Combine($path::GetDirectoryName($project.FileName), "App_Start\DataTablesMvc.cs")
$DTE.ItemOperations.OpenFile($appstart)
Loading…
Cancel
Save