Skip to content

Commit

Permalink
perf: stop populating obsolete subscribe fields (#4625)
Browse files Browse the repository at this point in the history
  • Loading branch information
sephrat authored Jun 22, 2022
1 parent 4d1ba5e commit 9a73463
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 59 deletions.
26 changes: 0 additions & 26 deletions src/Ombi.Core/Engine/MovieSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Threading.Tasks;

namespace Ombi.Core.Engine
Expand Down Expand Up @@ -216,34 +215,9 @@ protected async Task<SearchMovieViewModel> ProcessSingleMovie(SearchMovieViewMod

await RunSearchRules(viewMovie);

// This requires the rules to be run first to populate the RequestId property
await CheckForSubscription(viewMovie);

return viewMovie;
}

private async Task CheckForSubscription(SearchMovieViewModel viewModel)
{
// Check if this user requested it
var user = await GetUser();
if (user == null)
{
return;
}
var request = await RequestService.MovieRequestService.GetAll()
.AnyAsync(x => x.RequestedUserId.Equals(user.Id) && x.TheMovieDbId == viewModel.Id);
if (request || viewModel.Available)
{
viewModel.ShowSubscribe = false;
}
else
{
viewModel.ShowSubscribe = true;
var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s => s.UserId == user.Id
&& s.RequestId == viewModel.RequestId && s.RequestType == RequestType.Movie);
viewModel.Subscribed = sub != null;
}
}

private async Task<SearchMovieViewModel> ProcessSingleMovie(MovieDbSearchResult movie)
{
Expand Down
33 changes: 0 additions & 33 deletions src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,6 @@ private async Task<MovieFullInfoViewModel> ProcessSingleMovie(FullMovieInfo movi

await RunSearchRules(viewMovie);

// This requires the rules to be run first to populate the RequestId property
await CheckForSubscription(viewMovie);
var mapped = Mapper.Map<MovieFullInfoViewModel>(movie);

mapped.Available = viewMovie.Available;
Expand All @@ -415,8 +413,6 @@ private async Task<MovieFullInfoViewModel> ProcessSingleMovie(FullMovieInfo movi
mapped.PlexUrl = viewMovie.PlexUrl;
mapped.EmbyUrl = viewMovie.EmbyUrl;
mapped.JellyfinUrl = viewMovie.JellyfinUrl;
mapped.Subscribed = viewMovie.Subscribed;
mapped.ShowSubscribe = viewMovie.ShowSubscribe;
mapped.DigitalReleaseDate = viewMovie.DigitalReleaseDate;
mapped.RequestedDate4k = viewMovie.RequestedDate4k;
mapped.Approved4K = viewMovie.Approved4K;
Expand All @@ -438,8 +434,6 @@ private async Task<MovieCollectionsViewModel> ProcessCollection(Collections coll
var mappedMovie = Mapper.Map<SearchMovieViewModel>(movie);
await RunSearchRules(mappedMovie);

// This requires the rules to be run first to populate the RequestId property
await CheckForSubscription(mappedMovie);
var mapped = Mapper.Map<MovieCollection>(movie);

mapped.Available = movie.Available;
Expand All @@ -449,8 +443,6 @@ private async Task<MovieCollectionsViewModel> ProcessCollection(Collections coll
mapped.PlexUrl = movie.PlexUrl;
mapped.EmbyUrl = movie.EmbyUrl;
mapped.JellyfinUrl = movie.JellyfinUrl;
mapped.Subscribed = movie.Subscribed;
mapped.ShowSubscribe = movie.ShowSubscribe;
mapped.ReleaseDate = movie.ReleaseDate;
}
return viewMovie;
Expand Down Expand Up @@ -479,34 +471,9 @@ private async Task<SearchMovieViewModel> ProcessSingleMovie(SearchMovieViewModel

await RunSearchRules(viewMovie);

// This requires the rules to be run first to populate the RequestId property
await CheckForSubscription(viewMovie);

return viewMovie;
}

private async Task CheckForSubscription(SearchViewModel viewModel)
{
// Check if this user requested it
var user = await GetUser();
if (user == null)
{
return;
}
var request = await RequestService.MovieRequestService.GetAll()
.AnyAsync(x => x.RequestedUserId.Equals(user.Id) && x.TheMovieDbId == viewModel.Id);
if (request)
{
viewModel.ShowSubscribe = false;
}
else
{
viewModel.ShowSubscribe = true;
var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s => s.UserId == user.Id
&& s.RequestId == viewModel.RequestId && s.RequestType == RequestType.Movie);
viewModel.Subscribed = sub != null;
}
}

public async Task<MovieFullInfoViewModel> GetMovieInfoByImdbId(string imdbId, CancellationToken cancellationToken)
{
Expand Down
1 change: 1 addition & 0 deletions src/Ombi.Core/Models/Search/SearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class SearchViewModel
[Obsolete("Use request service instead")]
public bool Subscribed { get; set; }
[NotMapped]
[Obsolete("Use request service instead")]
public bool ShowSubscribe { get; set; }
}
}

0 comments on commit 9a73463

Please sign in to comment.