mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 08:16:05 -07:00
More for #2750
This commit is contained in:
parent
42662924d9
commit
e6e24c6a97
9 changed files with 60 additions and 27 deletions
|
@ -81,7 +81,7 @@ namespace Ombi.Store.Repository
|
||||||
await _ctx.Database.ExecuteSqlCommandAsync(sql);
|
await _ctx.Database.ExecuteSqlCommandAsync(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<int> InternalSaveChanges()
|
protected async Task<int> InternalSaveChanges()
|
||||||
{
|
{
|
||||||
return await GlobalMutex.Lock(async () => await _ctx.SaveChangesAsync());
|
return await GlobalMutex.Lock(async () => await _ctx.SaveChangesAsync());
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace Ombi.Store.Repository
|
||||||
public async Task Update(EmbyContent existingContent)
|
public async Task Update(EmbyContent existingContent)
|
||||||
{
|
{
|
||||||
Db.EmbyContent.Update(existingContent);
|
Db.EmbyContent.Update(existingContent);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<EmbyEpisode> GetAllEpisodes()
|
public IQueryable<EmbyEpisode> GetAllEpisodes()
|
||||||
|
@ -83,7 +83,7 @@ namespace Ombi.Store.Repository
|
||||||
public async Task<EmbyEpisode> Add(EmbyEpisode content)
|
public async Task<EmbyEpisode> Add(EmbyEpisode content)
|
||||||
{
|
{
|
||||||
await Db.EmbyEpisode.AddAsync(content);
|
await Db.EmbyEpisode.AddAsync(content);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
public async Task<EmbyEpisode> GetEpisodeByEmbyId(string key)
|
public async Task<EmbyEpisode> GetEpisodeByEmbyId(string key)
|
||||||
|
@ -94,12 +94,13 @@ namespace Ombi.Store.Repository
|
||||||
public async Task AddRange(IEnumerable<EmbyEpisode> content)
|
public async Task AddRange(IEnumerable<EmbyEpisode> content)
|
||||||
{
|
{
|
||||||
Db.EmbyEpisode.AddRange(content);
|
Db.EmbyEpisode.AddRange(content);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateWithoutSave(EmbyContent existingContent)
|
public void UpdateWithoutSave(EmbyContent existingContent)
|
||||||
{
|
{
|
||||||
Db.EmbyContent.Update(existingContent);
|
Db.EmbyContent.Update(existingContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -45,7 +45,7 @@ namespace Ombi.Store.Repository
|
||||||
Db.Attach(template);
|
Db.Attach(template);
|
||||||
Db.Entry(template).State = EntityState.Modified;
|
Db.Entry(template).State = EntityState.Modified;
|
||||||
}
|
}
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateRange(IEnumerable<NotificationTemplates> templates)
|
public async Task UpdateRange(IEnumerable<NotificationTemplates> templates)
|
||||||
|
@ -56,16 +56,21 @@ namespace Ombi.Store.Repository
|
||||||
Db.Attach(t);
|
Db.Attach(t);
|
||||||
Db.Entry(t).State = EntityState.Modified;
|
Db.Entry(t).State = EntityState.Modified;
|
||||||
}
|
}
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<NotificationTemplates> Insert(NotificationTemplates entity)
|
public async Task<NotificationTemplates> Insert(NotificationTemplates entity)
|
||||||
{
|
{
|
||||||
var settings = await Db.NotificationTemplates.AddAsync(entity).ConfigureAwait(false);
|
var settings = await Db.NotificationTemplates.AddAsync(entity).ConfigureAwait(false);
|
||||||
await Db.SaveChangesAsync().ConfigureAwait(false);
|
await InternalSaveChanges().ConfigureAwait(false);
|
||||||
return settings.Entity;
|
return settings.Entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<int> InternalSaveChanges()
|
||||||
|
{
|
||||||
|
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
|
||||||
|
}
|
||||||
|
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
// Protected implementation of Dispose pattern.
|
// Protected implementation of Dispose pattern.
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace Ombi.Store.Repository
|
||||||
public async Task Update(PlexServerContent existingContent)
|
public async Task Update(PlexServerContent existingContent)
|
||||||
{
|
{
|
||||||
Db.PlexServerContent.Update(existingContent);
|
Db.PlexServerContent.Update(existingContent);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
public void UpdateWithoutSave(PlexServerContent existingContent)
|
public void UpdateWithoutSave(PlexServerContent existingContent)
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,7 @@ namespace Ombi.Store.Repository
|
||||||
public async Task UpdateRange(IEnumerable<PlexServerContent> existingContent)
|
public async Task UpdateRange(IEnumerable<PlexServerContent> existingContent)
|
||||||
{
|
{
|
||||||
Db.PlexServerContent.UpdateRange(existingContent);
|
Db.PlexServerContent.UpdateRange(existingContent);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<PlexEpisode> GetAllEpisodes()
|
public IQueryable<PlexEpisode> GetAllEpisodes()
|
||||||
|
@ -127,14 +127,14 @@ namespace Ombi.Store.Repository
|
||||||
public async Task<PlexEpisode> Add(PlexEpisode content)
|
public async Task<PlexEpisode> Add(PlexEpisode content)
|
||||||
{
|
{
|
||||||
await Db.PlexEpisode.AddAsync(content);
|
await Db.PlexEpisode.AddAsync(content);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteEpisode(PlexEpisode content)
|
public async Task DeleteEpisode(PlexEpisode content)
|
||||||
{
|
{
|
||||||
Db.PlexEpisode.Remove(content);
|
Db.PlexEpisode.Remove(content);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PlexEpisode> GetEpisodeByKey(int key)
|
public async Task<PlexEpisode> GetEpisodeByKey(int key)
|
||||||
|
@ -144,7 +144,7 @@ namespace Ombi.Store.Repository
|
||||||
public async Task AddRange(IEnumerable<PlexEpisode> content)
|
public async Task AddRange(IEnumerable<PlexEpisode> content)
|
||||||
{
|
{
|
||||||
Db.PlexEpisode.AddRange(content);
|
Db.PlexEpisode.AddRange(content);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Ombi.Helpers;
|
||||||
using Ombi.Store.Context;
|
using Ombi.Store.Context;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
|
|
||||||
|
@ -70,12 +71,17 @@ namespace Ombi.Store.Repository.Requests
|
||||||
Db.MovieRequests.Attach(request);
|
Db.MovieRequests.Attach(request);
|
||||||
Db.Update(request);
|
Db.Update(request);
|
||||||
}
|
}
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Save()
|
public async Task Save()
|
||||||
{
|
{
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<int> InternalSaveChanges()
|
||||||
|
{
|
||||||
|
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Ombi.Helpers;
|
||||||
using Ombi.Store.Context;
|
using Ombi.Store.Context;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
|
|
||||||
|
@ -61,12 +62,16 @@ namespace Ombi.Store.Repository.Requests
|
||||||
Db.AlbumRequests.Attach(request);
|
Db.AlbumRequests.Attach(request);
|
||||||
Db.Update(request);
|
Db.Update(request);
|
||||||
}
|
}
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Save()
|
public async Task Save()
|
||||||
{
|
{
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
|
}
|
||||||
|
private async Task<int> InternalSaveChanges()
|
||||||
|
{
|
||||||
|
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Ombi.Helpers;
|
||||||
using Ombi.Store.Context;
|
using Ombi.Store.Context;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
|
|
||||||
|
@ -101,20 +102,20 @@ namespace Ombi.Store.Repository.Requests
|
||||||
|
|
||||||
public async Task Save()
|
public async Task Save()
|
||||||
{
|
{
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<TvRequests> Add(TvRequests request)
|
public async Task<TvRequests> Add(TvRequests request)
|
||||||
{
|
{
|
||||||
await Db.TvRequests.AddAsync(request);
|
await Db.TvRequests.AddAsync(request);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ChildRequests> AddChild(ChildRequests request)
|
public async Task<ChildRequests> AddChild(ChildRequests request)
|
||||||
{
|
{
|
||||||
await Db.ChildRequests.AddAsync(request);
|
await Db.ChildRequests.AddAsync(request);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
@ -122,33 +123,38 @@ namespace Ombi.Store.Repository.Requests
|
||||||
public async Task Delete(TvRequests request)
|
public async Task Delete(TvRequests request)
|
||||||
{
|
{
|
||||||
Db.TvRequests.Remove(request);
|
Db.TvRequests.Remove(request);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteChild(ChildRequests request)
|
public async Task DeleteChild(ChildRequests request)
|
||||||
{
|
{
|
||||||
Db.ChildRequests.Remove(request);
|
Db.ChildRequests.Remove(request);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteChildRange(IEnumerable<ChildRequests> request)
|
public async Task DeleteChildRange(IEnumerable<ChildRequests> request)
|
||||||
{
|
{
|
||||||
Db.ChildRequests.RemoveRange(request);
|
Db.ChildRequests.RemoveRange(request);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Update(TvRequests request)
|
public async Task Update(TvRequests request)
|
||||||
{
|
{
|
||||||
Db.Update(request);
|
Db.Update(request);
|
||||||
|
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateChild(ChildRequests request)
|
public async Task UpdateChild(ChildRequests request)
|
||||||
{
|
{
|
||||||
Db.Update(request);
|
Db.Update(request);
|
||||||
|
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<int> InternalSaveChanges()
|
||||||
|
{
|
||||||
|
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -62,14 +62,14 @@ namespace Ombi.Store.Repository
|
||||||
{
|
{
|
||||||
//_cache.Remove(GetName(entity.SettingsName));
|
//_cache.Remove(GetName(entity.SettingsName));
|
||||||
Db.Settings.Remove(entity);
|
Db.Settings.Remove(entity);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateAsync(GlobalSettings entity)
|
public async Task UpdateAsync(GlobalSettings entity)
|
||||||
{
|
{
|
||||||
//_cache.Remove(GetName(entity.SettingsName));
|
//_cache.Remove(GetName(entity.SettingsName));
|
||||||
Db.Update(entity);
|
Db.Update(entity);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Delete(GlobalSettings entity)
|
public void Delete(GlobalSettings entity)
|
||||||
|
@ -91,6 +91,11 @@ namespace Ombi.Store.Repository
|
||||||
return $"{entity}Json";
|
return $"{entity}Json";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<int> InternalSaveChanges()
|
||||||
|
{
|
||||||
|
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
|
||||||
|
}
|
||||||
|
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ using Ombi.Store.Entities;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Ombi.Helpers;
|
||||||
|
|
||||||
namespace Ombi.Store.Repository
|
namespace Ombi.Store.Repository
|
||||||
{
|
{
|
||||||
|
@ -19,12 +20,16 @@ namespace Ombi.Store.Repository
|
||||||
public async Task CreateToken(Tokens token)
|
public async Task CreateToken(Tokens token)
|
||||||
{
|
{
|
||||||
await Db.Tokens.AddAsync(token);
|
await Db.Tokens.AddAsync(token);
|
||||||
await Db.SaveChangesAsync();
|
await InternalSaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<Tokens> GetToken(string tokenId)
|
public IQueryable<Tokens> GetToken(string tokenId)
|
||||||
{
|
{
|
||||||
return Db.Tokens.Where(x => x.Token == tokenId);
|
return Db.Tokens.Where(x => x.Token == tokenId);
|
||||||
}
|
}
|
||||||
|
private async Task<int> InternalSaveChanges()
|
||||||
|
{
|
||||||
|
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue