diff --git a/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs b/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs index 2137dd329..2c0bedc45 100644 --- a/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs +++ b/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs @@ -79,11 +79,9 @@ namespace Ombi.Schedule.Jobs.Couchpotato await strat.ExecuteAsync(async () => { // Let's remove the old cached data - using (var tran = await _ctx.Database.BeginTransactionAsync()) - { - await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM CouchPotatoCache"); - tran.Commit(); - } + using var tran = await _ctx.Database.BeginTransactionAsync(); + await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM CouchPotatoCache"); + await tran.CommitAsync(); }); // Save @@ -107,13 +105,11 @@ namespace Ombi.Schedule.Jobs.Couchpotato strat = _ctx.Database.CreateExecutionStrategy(); await strat.ExecuteAsync(async () => { - using (var tran = await _ctx.Database.BeginTransactionAsync()) - { - await _ctx.CouchPotatoCache.AddRangeAsync(movieIds); + using var tran = await _ctx.Database.BeginTransactionAsync(); + await _ctx.CouchPotatoCache.AddRangeAsync(movieIds); - await _ctx.SaveChangesAsync(); - tran.Commit(); - } + await _ctx.SaveChangesAsync(); + await tran.CommitAsync(); }); await _notification.SendNotificationToAdmins("Couch Potato Sync Finished"); diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs index 87922efd9..6f81a4539 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs @@ -55,7 +55,7 @@ namespace Ombi.Schedule.Jobs.Lidarr using (var tran = await _ctx.Database.BeginTransactionAsync()) { await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM LidarrAlbumCache"); - tran.Commit(); + await tran.CommitAsync(); } }); @@ -85,7 +85,7 @@ namespace Ombi.Schedule.Jobs.Lidarr await _ctx.LidarrAlbumCache.AddRangeAsync(albumCache); await _ctx.SaveChangesAsync(); - tran.Commit(); + await tran.CommitAsync(); } }); } diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs index c4d9a3ee2..c8ef9e0f2 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs @@ -52,11 +52,9 @@ namespace Ombi.Schedule.Jobs.Lidarr await strat.ExecuteAsync(async () => { // Let's remove the old cached data - using (var tran = await _ctx.Database.BeginTransactionAsync()) - { - await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM LidarrArtistCache"); - tran.Commit(); - } + using var tran = await _ctx.Database.BeginTransactionAsync(); + await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM LidarrArtistCache"); + await tran.CommitAsync(); }); var artistCache = new List(); @@ -76,13 +74,11 @@ namespace Ombi.Schedule.Jobs.Lidarr strat = _ctx.Database.CreateExecutionStrategy(); await strat.ExecuteAsync(async () => { - using (var tran = await _ctx.Database.BeginTransactionAsync()) - { - await _ctx.LidarrArtistCache.AddRangeAsync(artistCache); + using var tran = await _ctx.Database.BeginTransactionAsync(); + await _ctx.LidarrArtistCache.AddRangeAsync(artistCache); - await _ctx.SaveChangesAsync(); - tran.Commit(); - } + await _ctx.SaveChangesAsync(); + await tran.CommitAsync(); }); } } diff --git a/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs b/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs index 94970305a..ef2975057 100644 --- a/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs +++ b/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs @@ -40,14 +40,10 @@ namespace Ombi.Schedule.Jobs.Radarr { try { - var strat = _ctx.Database.CreateExecutionStrategy(); - await strat.ExecuteAsync(async () => - { - // Let's remove the old cached data - using var tran = await _ctx.Database.BeginTransactionAsync(); - await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM RadarrCache"); - tran.Commit(); - }); + // Let's remove the old cached data + using var tran = await _ctx.Database.BeginTransactionAsync(); + await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM RadarrCache"); + await tran.CommitAsync(); var radarrSettings = _radarrSettings.GetSettingsAsync(); var radarr4kSettings = _radarr4kSettings.GetSettingsAsync(); diff --git a/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs b/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs index 91920dcd8..2882b7cf8 100644 --- a/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs +++ b/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs @@ -49,11 +49,9 @@ namespace Ombi.Schedule.Jobs.SickRage var strat = _ctx.Database.CreateExecutionStrategy(); await strat.ExecuteAsync(async () => { - using (var tran = await _ctx.Database.BeginTransactionAsync()) - { - await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SickRageCache"); - tran.Commit(); - } + using var tran = await _ctx.Database.BeginTransactionAsync(); + await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SickRageCache"); + await tran.CommitAsync(); }); var entites = ids.Select(id => new SickRageCache { TvDbId = id }).ToList(); @@ -84,12 +82,10 @@ namespace Ombi.Schedule.Jobs.SickRage strat = _ctx.Database.CreateExecutionStrategy(); await strat.ExecuteAsync(async () => { - using (var tran = await _ctx.Database.BeginTransactionAsync()) - { - await _ctx.SickRageEpisodeCache.AddRangeAsync(episodesToAdd); - await _ctx.SaveChangesAsync(); - tran.Commit(); - } + using var tran = await _ctx.Database.BeginTransactionAsync(); + await _ctx.SickRageEpisodeCache.AddRangeAsync(episodesToAdd); + await _ctx.SaveChangesAsync(); + await tran.CommitAsync(); }); } } diff --git a/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs b/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs index 2bda53875..969f2b6cd 100644 --- a/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs +++ b/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs @@ -69,7 +69,7 @@ namespace Ombi.Schedule.Jobs.Sonarr { using var tran = await _ctx.Database.BeginTransactionAsync(); await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrCache"); - tran.Commit(); + await tran.CommitAsync(); }); var sonarrCacheToSave = new HashSet(); @@ -97,7 +97,7 @@ namespace Ombi.Schedule.Jobs.Sonarr { using var tran = await _ctx.Database.BeginTransactionAsync(); await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrEpisodeCache"); - tran.Commit(); + await tran.CommitAsync(); }); foreach (var s in ids) @@ -156,7 +156,7 @@ namespace Ombi.Schedule.Jobs.Sonarr await _ctx.SonarrEpisodeCache.AddRangeAsync(episodesToAdd); _log.LogDebug("Commiting the transaction"); await _ctx.SaveChangesAsync(); - tran.Commit(); + await tran.CommitAsync(); }); } diff --git a/src/Ombi.Store/Context/OmbiContext.cs b/src/Ombi.Store/Context/OmbiContext.cs index 0139e2adc..eea83a03d 100644 --- a/src/Ombi.Store/Context/OmbiContext.cs +++ b/src/Ombi.Store/Context/OmbiContext.cs @@ -61,22 +61,20 @@ namespace Ombi.Store.Context var strat = Database.CreateExecutionStrategy(); strat.Execute(() => { - using (var tran = Database.BeginTransaction()) + using var tran = Database.BeginTransaction(); + // Make sure we have the API User + var apiUserExists = Users.ToList().Any(x => x.NormalizedUserName == "API"); + if (!apiUserExists) { - // Make sure we have the API User - var apiUserExists = Users.ToList().Any(x => x.NormalizedUserName == "API"); - if (!apiUserExists) + Users.Add(new OmbiUser { - Users.Add(new OmbiUser - { - UserName = "Api", - UserType = UserType.SystemUser, - NormalizedUserName = "API", - StreamingCountry = "US" - }); - SaveChanges(); - tran.Commit(); - } + UserName = "Api", + UserType = UserType.SystemUser, + NormalizedUserName = "API", + StreamingCountry = "US" + }); + SaveChanges(); + tran.Commit(); } }); @@ -233,11 +231,9 @@ namespace Ombi.Store.Context { strat.Execute(() => { - using (var tran = Database.BeginTransaction()) - { - SaveChanges(); - tran.Commit(); - } + using var tran = Database.BeginTransaction(); + SaveChanges(); + tran.Commit(); }); } }