Upcoming view will no longer hit the DB with the same request so many times.

pull/4/head
Mark McDowall 14 years ago
parent 3572855c34
commit c8ae3de292

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
@ -27,17 +28,25 @@ namespace NzbDrone.Web.Controllers
[GridAction] [GridAction]
public ActionResult _AjaxBindingYesterday() public ActionResult _AjaxBindingYesterday()
{ {
var upcoming = _upcomingEpisodesProvider.Yesterday().Select(e => new UpcomingEpisodeModel var upcomingDb = _upcomingEpisodesProvider.Yesterday();
var upcoming = new List<UpcomingEpisodeModel>();
foreach (var item in upcomingDb)
{
var series = item.Series;
upcoming.Add(new UpcomingEpisodeModel
{ {
SeriesId = e.Series.SeriesId, SeriesId = series.SeriesId,
EpisodeId = e.EpisodeId, EpisodeId = item.EpisodeId,
SeriesName = e.Series.Title, SeriesName = series.Title,
SeasonNumber = e.SeasonNumber, SeasonNumber = item.SeasonNumber,
EpisodeNumber = e.EpisodeNumber, EpisodeNumber = item.EpisodeNumber,
Title = e.Title, Title = item.Title,
Overview = e.Overview, Overview = item.Overview,
AirDate = e.AirDate.Add(Convert.ToDateTime(e.Series.AirTimes).TimeOfDay) AirDate = item.AirDate.Add(Convert.ToDateTime(series.AirTimes).TimeOfDay)
}); });
}
return View(new GridModel(upcoming)); return View(new GridModel(upcoming));
} }
@ -45,16 +54,25 @@ namespace NzbDrone.Web.Controllers
[GridAction] [GridAction]
public ActionResult _AjaxBindingToday() public ActionResult _AjaxBindingToday()
{ {
var upcoming = _upcomingEpisodesProvider.Today().Select(e => new UpcomingEpisodeModel var upcomingDb = _upcomingEpisodesProvider.Today();
var upcoming = new List<UpcomingEpisodeModel>();
foreach (var item in upcomingDb)
{
var series = item.Series;
upcoming.Add(new UpcomingEpisodeModel
{ {
SeriesId = e.Series.SeriesId, SeriesId = series.SeriesId,
SeriesName = e.Series.Title, EpisodeId = item.EpisodeId,
SeasonNumber = e.SeasonNumber, SeriesName = series.Title,
EpisodeNumber = e.EpisodeNumber, SeasonNumber = item.SeasonNumber,
Title = e.Title, EpisodeNumber = item.EpisodeNumber,
Overview = e.Overview, Title = item.Title,
AirDate = e.AirDate.Add(Convert.ToDateTime(e.Series.AirTimes).TimeOfDay) Overview = item.Overview,
AirDate = item.AirDate.Add(Convert.ToDateTime(series.AirTimes).TimeOfDay)
}); });
}
return View(new GridModel(upcoming)); return View(new GridModel(upcoming));
} }
@ -62,16 +80,25 @@ namespace NzbDrone.Web.Controllers
[GridAction] [GridAction]
public ActionResult _AjaxBindingTomorrow() public ActionResult _AjaxBindingTomorrow()
{ {
var upcoming = _upcomingEpisodesProvider.Tomorrow().Select(e => new UpcomingEpisodeModel var upcomingDb = _upcomingEpisodesProvider.Tomorrow();
var upcoming = new List<UpcomingEpisodeModel>();
foreach (var item in upcomingDb)
{
var series = item.Series;
upcoming.Add(new UpcomingEpisodeModel
{ {
SeriesId = e.Series.SeriesId, SeriesId = series.SeriesId,
SeriesName = e.Series.Title, EpisodeId = item.EpisodeId,
SeasonNumber = e.SeasonNumber, SeriesName = series.Title,
EpisodeNumber = e.EpisodeNumber, SeasonNumber = item.SeasonNumber,
Title = e.Title, EpisodeNumber = item.EpisodeNumber,
Overview = e.Overview, Title = item.Title,
AirDate = e.AirDate.Add(Convert.ToDateTime(e.Series.AirTimes).TimeOfDay) Overview = item.Overview,
AirDate = item.AirDate.Add(Convert.ToDateTime(series.AirTimes).TimeOfDay)
}); });
}
return View(new GridModel(upcoming)); return View(new GridModel(upcoming));
} }
@ -79,16 +106,25 @@ namespace NzbDrone.Web.Controllers
[GridAction] [GridAction]
public ActionResult _AjaxBindingWeek() public ActionResult _AjaxBindingWeek()
{ {
var upcoming = _upcomingEpisodesProvider.Week().Select(e => new UpcomingEpisodeModel var upcomingDb = _upcomingEpisodesProvider.Week();
var upcoming = new List<UpcomingEpisodeModel>();
foreach (var item in upcomingDb)
{
var series = item.Series;
upcoming.Add(new UpcomingEpisodeModel
{ {
SeriesId = e.Series.SeriesId, SeriesId = series.SeriesId,
SeriesName = e.Series.Title, EpisodeId = item.EpisodeId,
SeasonNumber = e.SeasonNumber, SeriesName = series.Title,
EpisodeNumber = e.EpisodeNumber, SeasonNumber = item.SeasonNumber,
Title = e.Title, EpisodeNumber = item.EpisodeNumber,
Overview = e.Overview, Title = item.Title,
AirDate = e.AirDate.Add(Convert.ToDateTime(e.Series.AirTimes).TimeOfDay) Overview = item.Overview,
AirDate = item.AirDate.Add(Convert.ToDateTime(series.AirTimes).TimeOfDay)
}); });
}
return View(new GridModel(upcoming)); return View(new GridModel(upcoming));
} }

Loading…
Cancel
Save