mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 17:22:54 -07:00
Potential fix for the DB locking issue #1720
This commit is contained in:
parent
1329a765ab
commit
6d5a823353
4 changed files with 46 additions and 28 deletions
|
@ -101,7 +101,7 @@ namespace Ombi.Notifications.Agents
|
|||
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = parsed.Message,
|
||||
Message = parsed.Message ?? string.Empty,
|
||||
};
|
||||
|
||||
await Send(notification, settings);
|
||||
|
|
|
@ -38,8 +38,8 @@ namespace Ombi.Schedule.Jobs.Plex
|
|||
|
||||
private async Task ProcessTv()
|
||||
{
|
||||
var tv = _tvRepo.GetChild().Where(x => !x.Available);
|
||||
var plexEpisodes = _repo.GetAllEpisodes().Include(x => x.Series);
|
||||
var tv = await _tvRepo.GetChild().Where(x => !x.Available).ToListAsync();
|
||||
var plexEpisodes = await _repo.GetAllEpisodes().Include(x => x.Series).ToListAsync();
|
||||
|
||||
foreach (var child in tv)
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ namespace Ombi.Schedule.Jobs.Plex
|
|||
private async Task ProcessMovies()
|
||||
{
|
||||
// Get all non available
|
||||
var movies = _movieRepo.GetAll().Where(x => !x.Available);
|
||||
var movies = await _movieRepo.GetAll().Where(x => !x.Available).ToListAsync();
|
||||
|
||||
foreach (var movie in movies)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Hangfire;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ombi.Api.Plex;
|
||||
using Ombi.Api.Plex.Models;
|
||||
|
@ -98,7 +99,7 @@ namespace Ombi.Schedule.Jobs.Plex
|
|||
var currentPosition = 0;
|
||||
var resultCount = settings.EpisodeBatchSize == 0 ? 50 : settings.EpisodeBatchSize;
|
||||
var episodes = await _api.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, section.key, currentPosition, resultCount);
|
||||
var currentData = _repo.GetAllEpisodes();
|
||||
var currentData = await _repo.GetAllEpisodes().ToListAsync();
|
||||
_log.LogInformation(LoggingEvents.PlexEpisodeCacher, $"Total Epsiodes found for {episodes.MediaContainer.librarySectionTitle} = {episodes.MediaContainer.totalSize}");
|
||||
|
||||
await ProcessEpsiodes(episodes, currentData);
|
||||
|
@ -118,7 +119,7 @@ namespace Ombi.Schedule.Jobs.Plex
|
|||
await _repo.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private async Task ProcessEpsiodes(PlexContainer episodes, IQueryable<PlexEpisode> currentEpisodes)
|
||||
private async Task ProcessEpsiodes(PlexContainer episodes, IEnumerable<PlexEpisode> currentEpisodes)
|
||||
{
|
||||
var ep = new HashSet<PlexEpisode>();
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Ombi.Core.Settings;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Repository;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace Ombi.Settings.Settings
|
||||
{
|
||||
|
@ -12,49 +13,63 @@ namespace Ombi.Settings.Settings
|
|||
where T : Models.Settings, new()
|
||||
{
|
||||
|
||||
public SettingsService(ISettingsRepository repo, IDataProtectionProvider provider)
|
||||
public SettingsService(ISettingsRepository repo, IMemoryCache cache)
|
||||
{
|
||||
Repo = repo;
|
||||
EntityName = typeof(T).Name;
|
||||
_protector = provider.CreateProtector(GetType().FullName);
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
private ISettingsRepository Repo { get; }
|
||||
private string EntityName { get; }
|
||||
private readonly IDataProtector _protector;
|
||||
private string CacheName => $"Settings{EntityName}";
|
||||
private readonly IMemoryCache _cache;
|
||||
|
||||
public T GetSettings()
|
||||
{
|
||||
return _cache.GetOrCreate(CacheName, entry =>
|
||||
{
|
||||
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(2);
|
||||
var result = Repo.Get(EntityName);
|
||||
if (result == null)
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
result.Content = DecryptSettings(result);
|
||||
var obj = string.IsNullOrEmpty(result.Content) ? null : JsonConvert.DeserializeObject<T>(result.Content, SerializerSettings.Settings);
|
||||
var obj = string.IsNullOrEmpty(result.Content)
|
||||
? null
|
||||
: JsonConvert.DeserializeObject<T>(result.Content, SerializerSettings.Settings);
|
||||
|
||||
var model = obj;
|
||||
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<T> GetSettingsAsync()
|
||||
{
|
||||
return await _cache.GetOrCreateAsync(CacheName, async entry =>
|
||||
{
|
||||
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(2);
|
||||
var result = await Repo.GetAsync(EntityName);
|
||||
if (result == null)
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
result.Content = DecryptSettings(result);
|
||||
var obj = string.IsNullOrEmpty(result.Content) ? null : JsonConvert.DeserializeObject<T>(result.Content, SerializerSettings.Settings);
|
||||
var obj = string.IsNullOrEmpty(result.Content)
|
||||
? null
|
||||
: JsonConvert.DeserializeObject<T>(result.Content, SerializerSettings.Settings);
|
||||
|
||||
var model = obj;
|
||||
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
public bool SaveSettings(T model)
|
||||
{
|
||||
_cache.Remove(CacheName);
|
||||
var entity = Repo.Get(EntityName);
|
||||
|
||||
if (entity == null)
|
||||
|
@ -81,6 +96,7 @@ namespace Ombi.Settings.Settings
|
|||
|
||||
public async Task<bool> SaveSettingsAsync(T model)
|
||||
{
|
||||
_cache.Remove(CacheName);
|
||||
var entity = await Repo.GetAsync(EntityName);
|
||||
|
||||
if (entity == null)
|
||||
|
@ -107,16 +123,17 @@ namespace Ombi.Settings.Settings
|
|||
|
||||
public void Delete(T model)
|
||||
{
|
||||
_cache.Remove(CacheName);
|
||||
var entity = Repo.Get(EntityName);
|
||||
if (entity != null)
|
||||
{
|
||||
Repo.Delete(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(T model)
|
||||
{
|
||||
_cache.Remove(CacheName);
|
||||
var entity = Repo.Get(EntityName);
|
||||
if (entity != null)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue