Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: stop populating obsolete subscribe fields from search endpoint #4625

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -393,8 +393,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 @@ -406,8 +404,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 @@ -429,8 +425,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 @@ -440,8 +434,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 @@ -470,34 +462,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; }
}
}