#254 Removed the cache, we are now storing the plex information into the database.

There is a big structure change around this, also increased the default check time to be in hours.
This commit is contained in:
tidusjar 2016-08-05 11:34:00 +01:00
commit 2608e53399
29 changed files with 479 additions and 170 deletions

View file

@ -53,8 +53,6 @@ using Nancy.Json;
using Ninject;
using StackExchange.Profiling;
namespace PlexRequests.UI
{
public class Bootstrapper : NinjectNancyBootstrapper
@ -88,10 +86,7 @@ namespace PlexRequests.UI
base.ApplicationStartup(container, pipelines);
#if DEBUG
pipelines.BeforeRequest += StartProfiler;
pipelines.AfterRequest += EndProfiler;
#endif
var settings = new SettingsServiceV2<PlexRequestSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
var baseUrl = settings.GetSettings().BaseUrl;
var redirect = string.IsNullOrEmpty(baseUrl) ? "~/login" : $"~/{baseUrl}/login";
@ -198,15 +193,5 @@ namespace PlexRequests.UI
loc.SetContainer(container);
}
private static Response StartProfiler(NancyContext ctx)
{
MiniProfiler.Start();
return null;
}
private static void EndProfiler(NancyContext ctx)
{
MiniProfiler.Stop();
}
}
}

View file

@ -1,50 +0,0 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: StringHelper.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System.Linq;
using System.Text.RegularExpressions;
namespace PlexRequests.UI.Helpers
{
public static class StringHelper
{
public static string FirstCharToUpper(this string input)
{
if (string.IsNullOrEmpty(input))
return input;
var firstUpper = char.ToUpper(input[0]);
return firstUpper + string.Join("", input.Skip(1));
}
public static string ToCamelCaseWords(this string input)
{
if (string.IsNullOrEmpty(input))
return input;
return Regex.Replace(input.FirstCharToUpper(), "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ");
}
}
}

View file

@ -608,10 +608,11 @@ namespace PlexRequests.UI.Modules
}
if (episodeRequest)
{
var cachedEpisodes = Checker.GetEpisodeCache().ToList();
var cachedEpisodesTask = await Checker.GetEpisodes();
var cachedEpisodes = cachedEpisodesTask.ToList();
foreach (var d in difference)
{
if (cachedEpisodes.Any(x => x.Episodes.SeasonNumber == d.SeasonNumber && x.Episodes.EpisodeNumber == d.EpisodeNumber && x.Episodes.ProviderId == providerId))
if (cachedEpisodes.Any(x => x.SeasonNumber == d.SeasonNumber && x.EpisodeNumber == d.EpisodeNumber && x.ProviderId == providerId))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullShowName} {d.SeasonNumber} - {d.EpisodeNumber} {Resources.UI.Search_AlreadyInPlex}" });
}
@ -983,15 +984,15 @@ namespace PlexRequests.UI.Modules
sonarrEpisodes = sonarrEp?.ToList() ?? new List<SonarrEpisodes>();
}
var plexCache = Checker.GetEpisodeCache(seriesId).ToList();
var plexCacheTask = await Checker.GetEpisodes(seriesId);
var plexCache = plexCacheTask.ToList();
foreach (var ep in seasons)
{
var requested = dbDbShow?.Episodes
.Any(episodesModel =>
ep.number == episodesModel.EpisodeNumber && ep.season == episodesModel.SeasonNumber) ?? false;
var alreadyInPlex = plexCache.Any(x => x.Episodes.EpisodeNumber == ep.number && x.Episodes.SeasonNumber == ep.season);
var alreadyInPlex = plexCache.Any(x => x.EpisodeNumber == ep.number && x.SeasonNumber == ep.season);
var inSonarr = sonarrEpisodes.Any(x => x.seasonNumber == ep.season && x.episodeNumber == ep.number && x.monitored);
model.Add(new EpisodeListViewModel

View file

@ -44,7 +44,6 @@ using PlexRequests.Helpers;
using PlexRequests.Helpers.Analytics;
using PlexRequests.UI.Models;
using StackExchange.Profiling;
using Action = PlexRequests.Helpers.Analytics.Action;
@ -78,17 +77,8 @@ namespace PlexRequests.UI.Modules
public async Task<Negotiator> Index()
{
var profiler = MiniProfiler.Current;
using (profiler.Step("Loading Index"))
{
using (profiler.Step("Loading AuthSettingsAsync and returning View"))
{
var settings = await AuthService.GetSettingsAsync();
return View["Index", settings];
}
}
var settings = await AuthService.GetSettingsAsync();
return View["Index", settings];
}
private async Task<Response> LoginUser()

View file

@ -65,14 +65,6 @@
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MiniProfiler, Version=3.0.10.0, Culture=neutral, PublicKeyToken=b44f9351044011a3, processorArchitecture=MSIL">
<HintPath>..\packages\MiniProfiler.3.0.10\lib\net40\MiniProfiler.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MiniProfiler.Mvc, Version=3.0.11.0, Culture=neutral, PublicKeyToken=b44f9351044011a3, processorArchitecture=MSIL">
<HintPath>..\packages\MiniProfiler.MVC4.3.0.11\lib\net40\MiniProfiler.Mvc.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Nancy, Version=1.4.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nancy.1.4.3\lib\net40\Nancy.dll</HintPath>
<Private>True</Private>
@ -219,7 +211,6 @@
<Compile Include="Helpers\HeadphonesSender.cs" />
<Compile Include="Helpers\AngularViewBase.cs" />
<Compile Include="Helpers\ServiceLocator.cs" />
<Compile Include="Helpers\StringHelper.cs" />
<Compile Include="Helpers\Themes.cs" />
<Compile Include="Helpers\TvSender.cs" />
<Compile Include="Helpers\ValidationHelper.cs" />

View file

@ -34,4 +34,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersionAttribute("1.0.0.0")]
[assembly: InternalsVisibleTo("PlexRequests.UI.Tests")]
[assembly: InternalsVisibleTo("PlexRequests.UI.Tests")]
[assembly: InternalsVisibleTo("PlexRequests.UI.Tests1")]
[assembly: InternalsVisibleTo("PlexRequests.Explorables")]

View file

@ -34,7 +34,7 @@
</div>
<div class="form-group">
<label for="PlexEpisodeCacher" class="control-label">Plex Episode Cacher (min)</label>
<label for="PlexEpisodeCacher" class="control-label">Plex Episode Cacher (hour)</label>
<input type="text" class="form-control form-control-custom " id="PlexEpisodeCacher" name="PlexEpisodeCacher" value="@Model.PlexEpisodeCacher">
</div>

View file

@ -1,5 +1,6 @@
@using System.Linq
@using PlexRequests.Core.Models
@using PlexRequests.Helpers
@using PlexRequests.UI.Helpers
@{
var baseUrl = Html.GetBaseUrl();

View file

@ -17,8 +17,6 @@
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Hosting" version="3.0.1" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="MiniProfiler" version="3.0.10" targetFramework="net45" />
<package id="MiniProfiler.MVC4" version="3.0.11" targetFramework="net45" />
<package id="Moment.js" version="2.9.0" targetFramework="net45" />
<package id="Mono.Posix" version="4.0.0.0" targetFramework="net45" />
<package id="Nancy" version="1.4.3" targetFramework="net45" />