mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-07 05:31:13 -07:00
#865 rework the backend data. Actually use real models rather than a JSON store.
This commit is contained in:
parent
08e389f590
commit
2bc916998c
55 changed files with 1277 additions and 702 deletions
|
@ -1,7 +1,5 @@
|
|||
using Ombi.Core.Engine.Interfaces;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Models.Requests.Movie;
|
||||
using Ombi.Core.Requests.Models;
|
||||
using Ombi.Core.Rules;
|
||||
using Ombi.Helpers;
|
||||
using System;
|
||||
|
@ -9,14 +7,18 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
using Ombi.Store.Repository;
|
||||
using Ombi.Store.Repository.Requests;
|
||||
|
||||
namespace Ombi.Core.Engine
|
||||
{
|
||||
public abstract class BaseMediaEngine : BaseEngine
|
||||
{
|
||||
private long _cacheTime;
|
||||
private Dictionary<int, MovieRequestModel> _dbMovies;
|
||||
private Dictionary<int, TvRequestModel> _dbTv;
|
||||
private Dictionary<int, MovieRequests> _dbMovies;
|
||||
private Dictionary<int, TvRequests> _dbTv;
|
||||
|
||||
protected BaseMediaEngine(IPrincipal identity, IRequestServiceMain requestService,
|
||||
IRuleEvaluator rules) : base(identity, rules)
|
||||
|
@ -25,32 +27,32 @@ namespace Ombi.Core.Engine
|
|||
}
|
||||
|
||||
protected IRequestServiceMain RequestService { get; }
|
||||
protected IRequestService<MovieRequestModel> MovieRequestService => RequestService.MovieRequestService;
|
||||
protected IRequestService<TvRequestModel> TvRequestService => RequestService.TvRequestService;
|
||||
protected IMovieRequestRepository MovieRepository => RequestService.MovieRequestService;
|
||||
protected ITvRequestRepository TvRepository => RequestService.TvRequestService;
|
||||
|
||||
protected async Task<Dictionary<int, MovieRequestModel>> GetMovieRequests()
|
||||
protected async Task<Dictionary<int, MovieRequests>> GetMovieRequests()
|
||||
{
|
||||
var now = DateTime.Now.Ticks;
|
||||
if (_dbMovies == null || now - _cacheTime > 10000)
|
||||
{
|
||||
var allResults = await MovieRequestService.GetAllAsync();
|
||||
var allResults = await MovieRepository.Get().ToListAsync();
|
||||
|
||||
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
||||
_dbMovies = distinctResults.ToDictionary(x => x.ProviderId);
|
||||
var distinctResults = allResults.DistinctBy(x => x.TheMovieDbId);
|
||||
_dbMovies = distinctResults.ToDictionary(x => x.TheMovieDbId);
|
||||
_cacheTime = now;
|
||||
}
|
||||
return _dbMovies;
|
||||
}
|
||||
|
||||
protected async Task<Dictionary<int, TvRequestModel>> GetTvRequests()
|
||||
protected async Task<Dictionary<int, TvRequests>> GetTvRequests()
|
||||
{
|
||||
var now = DateTime.Now.Ticks;
|
||||
if (_dbTv == null || now - _cacheTime > 10000)
|
||||
{
|
||||
var allResults = await TvRequestService.GetAllAsync();
|
||||
var allResults = await TvRepository.Get().ToListAsync();
|
||||
|
||||
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
||||
_dbTv = distinctResults.ToDictionary(x => x.ProviderId);
|
||||
var distinctResults = allResults.DistinctBy(x => x.TvDbId);
|
||||
_dbTv = distinctResults.ToDictionary(x => x.TvDbId);
|
||||
_cacheTime = now;
|
||||
}
|
||||
return _dbTv;
|
||||
|
@ -58,16 +60,34 @@ namespace Ombi.Core.Engine
|
|||
|
||||
public RequestCountModel RequestCount()
|
||||
{
|
||||
var movieQuery = MovieRequestService.GetAllQueryable();
|
||||
var tvQuery = MovieRequestService.GetAllQueryable();
|
||||
var movieQuery = MovieRepository.Get();
|
||||
var tvQuery = TvRepository.Get();
|
||||
|
||||
var pendingMovies = movieQuery.Count(x => !x.Approved && !x.Available);
|
||||
var approvedMovies = movieQuery.Count(x => x.Approved && !x.Available);
|
||||
var availableMovies = movieQuery.Count(x => x.Available);
|
||||
|
||||
var pendingTv = tvQuery.Count(x => !x.Approved && !x.Available);
|
||||
var approvedTv = tvQuery.Count(x => x.Approved && !x.Available);
|
||||
var availableTv = tvQuery.Count(x => x.Available);
|
||||
var pendingTv = 0;
|
||||
var approvedTv = 0;
|
||||
var availableTv = 0;
|
||||
foreach (var tv in tvQuery)
|
||||
{
|
||||
foreach (var child in tv.ChildRequests)
|
||||
{
|
||||
if (!child.Approved && !child.Available)
|
||||
{
|
||||
pendingTv++;
|
||||
}
|
||||
if (child.Approved && !child.Available)
|
||||
{
|
||||
approvedTv++;
|
||||
}
|
||||
if (child.Available)
|
||||
{
|
||||
availableTv++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new RequestCountModel
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue