pull/2922/head
Jamie Rees 6 years ago
parent 42662924d9
commit e6e24c6a97

@ -81,7 +81,7 @@ namespace Ombi.Store.Repository
await _ctx.Database.ExecuteSqlCommandAsync(sql);
}
private async Task<int> InternalSaveChanges()
protected async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await _ctx.SaveChangesAsync());
}

@ -72,7 +72,7 @@ namespace Ombi.Store.Repository
public async Task Update(EmbyContent existingContent)
{
Db.EmbyContent.Update(existingContent);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public IQueryable<EmbyEpisode> GetAllEpisodes()
@ -83,7 +83,7 @@ namespace Ombi.Store.Repository
public async Task<EmbyEpisode> Add(EmbyEpisode content)
{
await Db.EmbyEpisode.AddAsync(content);
await Db.SaveChangesAsync();
await InternalSaveChanges();
return content;
}
public async Task<EmbyEpisode> GetEpisodeByEmbyId(string key)
@ -94,12 +94,13 @@ namespace Ombi.Store.Repository
public async Task AddRange(IEnumerable<EmbyEpisode> content)
{
Db.EmbyEpisode.AddRange(content);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public void UpdateWithoutSave(EmbyContent existingContent)
{
Db.EmbyContent.Update(existingContent);
}
}
}

@ -45,7 +45,7 @@ namespace Ombi.Store.Repository
Db.Attach(template);
Db.Entry(template).State = EntityState.Modified;
}
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task UpdateRange(IEnumerable<NotificationTemplates> templates)
@ -56,16 +56,21 @@ namespace Ombi.Store.Repository
Db.Attach(t);
Db.Entry(t).State = EntityState.Modified;
}
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task<NotificationTemplates> Insert(NotificationTemplates entity)
{
var settings = await Db.NotificationTemplates.AddAsync(entity).ConfigureAwait(false);
await Db.SaveChangesAsync().ConfigureAwait(false);
await InternalSaveChanges().ConfigureAwait(false);
return settings.Entity;
}
private async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
}
private bool _disposed;
// Protected implementation of Dispose pattern.
protected virtual void Dispose(bool disposing)

@ -96,7 +96,7 @@ namespace Ombi.Store.Repository
public async Task Update(PlexServerContent existingContent)
{
Db.PlexServerContent.Update(existingContent);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public void UpdateWithoutSave(PlexServerContent existingContent)
{
@ -106,7 +106,7 @@ namespace Ombi.Store.Repository
public async Task UpdateRange(IEnumerable<PlexServerContent> existingContent)
{
Db.PlexServerContent.UpdateRange(existingContent);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public IQueryable<PlexEpisode> GetAllEpisodes()
@ -127,14 +127,14 @@ namespace Ombi.Store.Repository
public async Task<PlexEpisode> Add(PlexEpisode content)
{
await Db.PlexEpisode.AddAsync(content);
await Db.SaveChangesAsync();
await InternalSaveChanges();
return content;
}
public async Task DeleteEpisode(PlexEpisode content)
{
Db.PlexEpisode.Remove(content);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task<PlexEpisode> GetEpisodeByKey(int key)
@ -144,7 +144,7 @@ namespace Ombi.Store.Repository
public async Task AddRange(IEnumerable<PlexEpisode> content)
{
Db.PlexEpisode.AddRange(content);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Helpers;
using Ombi.Store.Context;
using Ombi.Store.Entities.Requests;
@ -70,12 +71,17 @@ namespace Ombi.Store.Repository.Requests
Db.MovieRequests.Attach(request);
Db.Update(request);
}
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
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.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Helpers;
using Ombi.Store.Context;
using Ombi.Store.Entities.Requests;
@ -61,12 +62,16 @@ namespace Ombi.Store.Repository.Requests
Db.AlbumRequests.Attach(request);
Db.Update(request);
}
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
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.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Helpers;
using Ombi.Store.Context;
using Ombi.Store.Entities.Requests;
@ -101,20 +102,20 @@ namespace Ombi.Store.Repository.Requests
public async Task Save()
{
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task<TvRequests> Add(TvRequests request)
{
await Db.TvRequests.AddAsync(request);
await Db.SaveChangesAsync();
await InternalSaveChanges();
return request;
}
public async Task<ChildRequests> AddChild(ChildRequests request)
{
await Db.ChildRequests.AddAsync(request);
await Db.SaveChangesAsync();
await InternalSaveChanges();
return request;
}
@ -122,33 +123,38 @@ namespace Ombi.Store.Repository.Requests
public async Task Delete(TvRequests request)
{
Db.TvRequests.Remove(request);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task DeleteChild(ChildRequests request)
{
Db.ChildRequests.Remove(request);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task DeleteChildRange(IEnumerable<ChildRequests> request)
{
Db.ChildRequests.RemoveRange(request);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task Update(TvRequests request)
{
Db.Update(request);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task UpdateChild(ChildRequests 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));
Db.Settings.Remove(entity);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public async Task UpdateAsync(GlobalSettings entity)
{
//_cache.Remove(GetName(entity.SettingsName));
Db.Update(entity);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public void Delete(GlobalSettings entity)
@ -91,6 +91,11 @@ namespace Ombi.Store.Repository
return $"{entity}Json";
}
private async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
}
private bool _disposed;
protected virtual void Dispose(bool disposing)
{

@ -4,6 +4,7 @@ using Ombi.Store.Entities;
using System;
using System.Linq;
using System.Threading.Tasks;
using Ombi.Helpers;
namespace Ombi.Store.Repository
{
@ -19,12 +20,16 @@ namespace Ombi.Store.Repository
public async Task CreateToken(Tokens token)
{
await Db.Tokens.AddAsync(token);
await Db.SaveChangesAsync();
await InternalSaveChanges();
}
public IQueryable<Tokens> GetToken(string tokenId)
{
return Db.Tokens.Where(x => x.Token == tokenId);
}
private async Task<int> InternalSaveChanges()
{
return await GlobalMutex.Lock(async () => await Db.SaveChangesAsync());
}
}
}

Loading…
Cancel
Save