mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 21:33:15 -07:00
merge develop into v4
This commit is contained in:
commit
6a3addae5c
52 changed files with 1529 additions and 344 deletions
|
@ -63,7 +63,12 @@ namespace Ombi.Store.Context
|
|||
{
|
||||
// VACUUM;
|
||||
Database.ExecuteSqlCommand("VACUUM;");
|
||||
SaveChanges();
|
||||
|
||||
using (var tran = Database.BeginTransaction())
|
||||
{
|
||||
SaveChanges();
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -89,18 +89,23 @@ namespace Ombi.Store.Context
|
|||
|
||||
public void Seed()
|
||||
{
|
||||
// Make sure we have the API User
|
||||
var apiUserExists = Users.Any(x => x.UserName.Equals("Api", StringComparison.CurrentCultureIgnoreCase));
|
||||
if (!apiUserExists)
|
||||
{
|
||||
Users.Add(new OmbiUser
|
||||
{
|
||||
UserName = "Api",
|
||||
UserType = UserType.SystemUser,
|
||||
NormalizedUserName = "API",
|
||||
|
||||
});
|
||||
SaveChanges();
|
||||
using (var tran = Database.BeginTransaction())
|
||||
{
|
||||
// Make sure we have the API User
|
||||
var apiUserExists = Users.Any(x => x.UserName.Equals("Api", StringComparison.CurrentCultureIgnoreCase));
|
||||
if (!apiUserExists)
|
||||
{
|
||||
Users.Add(new OmbiUser
|
||||
{
|
||||
UserName = "Api",
|
||||
UserType = UserType.SystemUser,
|
||||
NormalizedUserName = "API",
|
||||
|
||||
});
|
||||
SaveChanges();
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
//Check if templates exist
|
||||
|
@ -238,7 +243,12 @@ namespace Ombi.Store.Context
|
|||
|
||||
if (needToSave)
|
||||
{
|
||||
SaveChanges();
|
||||
|
||||
using (var tran = Database.BeginTransaction())
|
||||
{
|
||||
SaveChanges();
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,36 +33,44 @@ namespace Ombi.Store.Context
|
|||
|
||||
public void Seed()
|
||||
{
|
||||
// Add the tokens
|
||||
var fanArt = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);
|
||||
if (fanArt == null)
|
||||
|
||||
using (var tran = Database.BeginTransaction())
|
||||
{
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
// Add the tokens
|
||||
var fanArt = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);
|
||||
if (fanArt == null)
|
||||
{
|
||||
Type = ConfigurationTypes.FanartTv,
|
||||
Value = "4b6d983efa54d8f45c68432521335f15"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
var movieDb = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);
|
||||
if (movieDb == null)
|
||||
{
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
{
|
||||
Type = ConfigurationTypes.FanartTv,
|
||||
Value = "4b6d983efa54d8f45c68432521335f15"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
var movieDb = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);
|
||||
if (movieDb == null)
|
||||
{
|
||||
Type = ConfigurationTypes.TheMovieDb,
|
||||
Value = "b8eabaf5608b88d0298aa189dd90bf00"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
var notification = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.Notification);
|
||||
if (notification == null)
|
||||
{
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
{
|
||||
Type = ConfigurationTypes.TheMovieDb,
|
||||
Value = "b8eabaf5608b88d0298aa189dd90bf00"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
var notification =
|
||||
ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.Notification);
|
||||
if (notification == null)
|
||||
{
|
||||
Type = ConfigurationTypes.Notification,
|
||||
Value = "4f0260c4-9c3d-41ab-8d68-27cb5a593f0e"
|
||||
});
|
||||
SaveChanges();
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
{
|
||||
Type = ConfigurationTypes.Notification,
|
||||
Value = "4f0260c4-9c3d-41ab-8d68-27cb5a593f0e"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||
<PackageReference Include="Nito.AsyncEx" Version="5.0.0-pre-05" />
|
||||
<PackageReference Include="Polly" Version="7.1.0" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="1.1.9" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -24,16 +24,20 @@ namespace Ombi.Store.Repository
|
|||
|
||||
public async Task Record(AuditType type, AuditArea area, string description, string user)
|
||||
{
|
||||
await Ctx.Audit.AddAsync(new Audit
|
||||
using (var tran = await Ctx.Database.BeginTransactionAsync())
|
||||
{
|
||||
User = user,
|
||||
AuditArea = area,
|
||||
AuditType = type,
|
||||
DateTime = DateTime.UtcNow,
|
||||
Description = description
|
||||
});
|
||||
await Ctx.Audit.AddAsync(new Audit
|
||||
{
|
||||
User = user,
|
||||
AuditArea = area,
|
||||
AuditType = type,
|
||||
DateTime = DateTime.UtcNow,
|
||||
Description = description
|
||||
});
|
||||
|
||||
await Ctx.SaveChangesAsync();
|
||||
await Ctx.SaveChangesAsync();
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Context;
|
||||
using Ombi.Store.Entities;
|
||||
using Polly;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
|
@ -83,7 +85,25 @@ namespace Ombi.Store.Repository
|
|||
|
||||
protected async Task<int> InternalSaveChanges()
|
||||
{
|
||||
return await _ctx.SaveChangesAsync();
|
||||
var policy = Policy
|
||||
.Handle<SqliteException>()
|
||||
.WaitAndRetryAsync(new[]
|
||||
{
|
||||
TimeSpan.FromSeconds(1),
|
||||
TimeSpan.FromSeconds(2),
|
||||
TimeSpan.FromSeconds(3)
|
||||
});
|
||||
|
||||
var result = await policy.ExecuteAndCaptureAsync(async () =>
|
||||
{
|
||||
using (var tran = await _ctx.Database.BeginTransactionAsync())
|
||||
{
|
||||
var r = await _ctx.SaveChangesAsync();
|
||||
tran.Commit();
|
||||
return r;
|
||||
}
|
||||
});
|
||||
return result.Result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ using Ombi.Store.Entities.Requests;
|
|||
|
||||
namespace Ombi.Store.Repository.Requests
|
||||
{
|
||||
public class TvRequestRepository : ITvRequestRepository
|
||||
public class TvRequestRepository : BaseRepository<TvRequests, IOmbiContext>, ITvRequestRepository
|
||||
{
|
||||
public TvRequestRepository(IOmbiContext ctx)
|
||||
public TvRequestRepository(IOmbiContext ctx) : base(ctx)
|
||||
{
|
||||
Db = ctx;
|
||||
}
|
||||
|
@ -151,10 +151,5 @@ namespace Ombi.Store.Repository.Requests
|
|||
|
||||
await InternalSaveChanges();
|
||||
}
|
||||
|
||||
private async Task<int> InternalSaveChanges()
|
||||
{
|
||||
return await Db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,17 +24,28 @@ namespace Ombi.Store.Repository
|
|||
public GlobalSettings Insert(GlobalSettings entity)
|
||||
{
|
||||
//_cache.Remove(GetName(entity.SettingsName));
|
||||
var settings = Db.Settings.Add(entity);
|
||||
Db.SaveChanges();
|
||||
return settings.Entity;
|
||||
|
||||
using (var tran = Db.Database.BeginTransaction())
|
||||
{
|
||||
var settings = Db.Settings.Add(entity);
|
||||
Db.SaveChanges();
|
||||
tran.Commit();
|
||||
return settings.Entity;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<GlobalSettings> InsertAsync(GlobalSettings entity)
|
||||
{
|
||||
//_cache.Remove(GetName(entity.SettingsName));
|
||||
var settings = await Db.Settings.AddAsync(entity).ConfigureAwait(false);
|
||||
await Db.SaveChangesAsync().ConfigureAwait(false);
|
||||
return settings.Entity;
|
||||
|
||||
using (var tran = Db.Database.BeginTransaction())
|
||||
{
|
||||
//_cache.Remove(GetName(entity.SettingsName));
|
||||
var settings = await Db.Settings.AddAsync(entity);
|
||||
await Db.SaveChangesAsync();
|
||||
tran.Commit();
|
||||
|
||||
return settings.Entity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,8 +54,8 @@ namespace Ombi.Store.Repository
|
|||
//return _cache.GetOrCreate(GetName(pageName), entry =>
|
||||
//{
|
||||
// entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(1);
|
||||
var entity = Db.Settings.AsNoTracking().FirstOrDefault(x => x.SettingsName == pageName);
|
||||
return entity;
|
||||
var entity = Db.Settings.AsNoTracking().FirstOrDefault(x => x.SettingsName == pageName);
|
||||
return entity;
|
||||
//});
|
||||
}
|
||||
|
||||
|
@ -52,9 +63,9 @@ namespace Ombi.Store.Repository
|
|||
{
|
||||
//return await _cache.GetOrCreateAsync(GetName(settingsName), async entry =>
|
||||
//{
|
||||
//entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(1);
|
||||
var obj = await Db.Settings.AsNoTracking().FirstOrDefaultAsync(x => x.SettingsName == settingsName);
|
||||
return obj;
|
||||
//entry.AbsoluteExpiration = DateTimeOffset.Now.AddHours(1);
|
||||
var obj = await Db.Settings.AsNoTracking().FirstOrDefaultAsync(x => x.SettingsName == settingsName);
|
||||
return obj;
|
||||
//});
|
||||
}
|
||||
|
||||
|
@ -75,15 +86,24 @@ namespace Ombi.Store.Repository
|
|||
public void Delete(GlobalSettings entity)
|
||||
{
|
||||
//_cache.Remove(GetName(entity.SettingsName));
|
||||
Db.Settings.Remove(entity);
|
||||
Db.SaveChanges();
|
||||
|
||||
using (var tran = Db.Database.BeginTransaction())
|
||||
{
|
||||
Db.Settings.Remove(entity);
|
||||
Db.SaveChanges();
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(GlobalSettings entity)
|
||||
{
|
||||
Db.Update(entity);
|
||||
//_cache.Remove(GetName(entity.SettingsName));
|
||||
Db.SaveChanges();
|
||||
using (var tran = Db.Database.BeginTransaction())
|
||||
{
|
||||
Db.Update(entity);
|
||||
//_cache.Remove(GetName(entity.SettingsName));
|
||||
Db.SaveChanges();
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetName(string entity)
|
||||
|
@ -93,7 +113,13 @@ namespace Ombi.Store.Repository
|
|||
|
||||
private async Task<int> InternalSaveChanges()
|
||||
{
|
||||
return await Db.SaveChangesAsync();
|
||||
|
||||
using (var tran = Db.Database.BeginTransaction())
|
||||
{
|
||||
var r = await Db.SaveChangesAsync();
|
||||
tran.Commit();
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _disposed;
|
||||
|
|
|
@ -8,9 +8,9 @@ using Ombi.Helpers;
|
|||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class TokenRepository : ITokenRepository
|
||||
public class TokenRepository : BaseRepository<Tokens, IOmbiContext>, ITokenRepository
|
||||
{
|
||||
public TokenRepository(IOmbiContext db)
|
||||
public TokenRepository(IOmbiContext db) : base(db)
|
||||
{
|
||||
Db = db;
|
||||
}
|
||||
|
@ -27,9 +27,5 @@ namespace Ombi.Store.Repository
|
|||
{
|
||||
return Db.Tokens.Where(x => x.Token == tokenId);
|
||||
}
|
||||
private async Task<int> InternalSaveChanges()
|
||||
{
|
||||
return await Db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue