fix(database): Just some tweaks, shouldn't notice any difference, maybe a less error in the log

pull/4848/head
tidusjar 2 years ago
parent fd1b2ba2ab
commit 67fb9921c0

@ -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");

@ -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();
}
});
}

@ -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<LidarrArtistCache>();
@ -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();
});
}
}

@ -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();

@ -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();
});
}
}

@ -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<SonarrCache>();
@ -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();
});
}

@ -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();
});
}
}

Loading…
Cancel
Save