UnitOfWork compltely removed. GetDbContext now returns a NadekoContext. Changed every access to contect via uow._context to uow

This commit is contained in:
Kwoth
2021-06-19 05:16:27 +02:00
parent 51a4499809
commit c127dcd1e3
81 changed files with 404 additions and 512 deletions

View File

@@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Searches.Services
using (var uow = db.GetDbContext())
{
var guildConfigIds = bot.AllGuildConfigs.Select(x => x.Id).ToList();
_subs = uow._context.GuildConfigs
_subs = uow.GuildConfigs
.AsQueryable()
.Where(x => guildConfigIds.Contains(x.Id))
.Include(x => x.FeedSubs)
@@ -167,7 +167,7 @@ namespace NadekoBot.Modules.Searches.Services
{
using (var uow = _db.GetDbContext())
{
return uow._context.GuildConfigsForId(guildId,
return uow.GuildConfigsForId(guildId,
set => set.Include(x => x.FeedSubs)
.ThenInclude(x => x.GuildConfig))
.FeedSubs
@@ -188,7 +188,7 @@ namespace NadekoBot.Modules.Searches.Services
using (var uow = _db.GetDbContext())
{
var gc = uow._context.GuildConfigsForId(guildId,
var gc = uow.GuildConfigsForId(guildId,
set => set.Include(x => x.FeedSubs)
.ThenInclude(x => x.GuildConfig));
@@ -224,7 +224,7 @@ namespace NadekoBot.Modules.Searches.Services
using (var uow = _db.GetDbContext())
{
var items = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.FeedSubs))
var items = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FeedSubs))
.FeedSubs
.OrderBy(x => x.Id)
.ToList();
@@ -237,7 +237,7 @@ namespace NadekoBot.Modules.Searches.Services
old.Remove(toRemove);
return old;
});
uow._context.Remove(toRemove);
uow.Remove(toRemove);
uow.SaveChanges();
}

View File

@@ -410,7 +410,7 @@ namespace NadekoBot.Modules.Searches.Services
bool added;
using (var uow = _db.GetDbContext())
{
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(y => y.NsfwBlacklistedTags));
var gc = uow.GuildConfigsForId(guildId, set => set.Include(y => y.NsfwBlacklistedTags));
if (gc.NsfwBlacklistedTags.Add(tagObj))
added = true;
else
@@ -418,7 +418,7 @@ namespace NadekoBot.Modules.Searches.Services
gc.NsfwBlacklistedTags.Remove(tagObj);
var toRemove = gc.NsfwBlacklistedTags.FirstOrDefault(x => x.Equals(tagObj));
if (toRemove != null)
uow._context.Remove(toRemove);
uow.Remove(toRemove);
added = false;
}
var newTags = new HashSet<string>(gc.NsfwBlacklistedTags.Select(x => x.Tag));

View File

@@ -57,7 +57,7 @@ namespace NadekoBot.Modules.Searches.Services
using (var uow = db.GetDbContext())
{
var ids = client.GetGuildIds();
var guildConfigs = uow._context.Set<GuildConfig>()
var guildConfigs = uow.Set<GuildConfig>()
.AsQueryable()
.Include(x => x.FollowedStreams)
.Where(x => ids.Contains(x.GuildId))
@@ -83,7 +83,7 @@ namespace NadekoBot.Modules.Searches.Services
// shard 0 will keep track of when there are no more guilds which track a stream
if (client.ShardId == 0)
{
var allFollowedStreams = uow._context.Set<FollowedStream>()
var allFollowedStreams = uow.Set<FollowedStream>()
.AsQueryable()
.ToList();
@@ -132,12 +132,12 @@ namespace NadekoBot.Modules.Searches.Services
Log.Information($"Deleting {kvp.Value.Count} {kvp.Key} streams because " +
$"they've been erroring for more than {errorLimit}: {string.Join(", ", kvp.Value)}");
var toDelete = uow._context.Set<FollowedStream>()
var toDelete = uow.Set<FollowedStream>()
.AsQueryable()
.Where(x => x.Type == kvp.Key && kvp.Value.Contains(x.Username))
.ToList();
uow._context.RemoveRange(toDelete);
uow.RemoveRange(toDelete);
uow.SaveChanges();
foreach(var loginToDelete in kvp.Value)
@@ -293,7 +293,7 @@ namespace NadekoBot.Modules.Searches.Services
{
using (var uow = _db.GetDbContext())
{
var gc = uow._context.GuildConfigs
var gc = uow.GuildConfigs
.AsQueryable()
.Include(x => x.FollowedStreams)
.FirstOrDefault(x => x.GuildId == guildConfig.GuildId);
@@ -320,7 +320,7 @@ namespace NadekoBot.Modules.Searches.Services
{
using (var uow = _db.GetDbContext())
{
var gc = uow._context.GuildConfigsForId(guild.Id, set => set.Include(x => x.FollowedStreams));
var gc = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.FollowedStreams));
_offlineNotificationServers.TryRemove(gc.GuildId);
@@ -342,7 +342,7 @@ namespace NadekoBot.Modules.Searches.Services
int count;
using (var uow = _db.GetDbContext())
{
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));
count = gc.FollowedStreams.Count;
gc.FollowedStreams.Clear();
uow.SaveChanges();
@@ -356,7 +356,7 @@ namespace NadekoBot.Modules.Searches.Services
FollowedStream fs;
using (var uow = _db.GetDbContext())
{
var fss = uow._context.Set<FollowedStream>()
var fss = uow.Set<FollowedStream>()
.AsQueryable()
.Where(x => x.GuildId == guildId)
.OrderBy(x => x.Id)
@@ -367,7 +367,7 @@ namespace NadekoBot.Modules.Searches.Services
return null;
fs = fss[index];
uow._context.Remove(fs);
uow.Remove(fs);
await uow.SaveChangesAsync();
@@ -411,7 +411,7 @@ namespace NadekoBot.Modules.Searches.Services
FollowedStream fs;
using (var uow = _db.GetDbContext())
{
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));
// add it to the database
fs = new FollowedStream()
@@ -481,7 +481,7 @@ namespace NadekoBot.Modules.Searches.Services
bool newValue;
using (var uow = _db.GetDbContext())
{
var gc = uow._context.GuildConfigsForId(guildId, set => set);
var gc = uow.GuildConfigsForId(guildId, set => set);
newValue = gc.NotifyStreamOffline = !gc.NotifyStreamOffline;
uow.SaveChanges();
@@ -530,7 +530,7 @@ namespace NadekoBot.Modules.Searches.Services
{
using (var uow = _db.GetDbContext())
{
var fss = uow._context.Set<FollowedStream>()
var fss = uow.Set<FollowedStream>()
.AsQueryable()
.Where(x => x.GuildId == guildId)
.OrderBy(x => x.Id)
@@ -564,7 +564,7 @@ namespace NadekoBot.Modules.Searches.Services
{
using var uow = _db.GetDbContext();
var all = uow._context.Set<FollowedStream>()
var all = uow.Set<FollowedStream>()
.ToList();
if (all.Count == 0)

View File

@@ -88,7 +88,7 @@ namespace NadekoBot.Modules.Searches.Services
//
// using(var uow = _db.GetDbContext())
// {
// var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.YtFollowedChannels));
// var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.YtFollowedChannels));
//
// // see if this yt channel was already followed on this discord channel
// var oldObj = gc.YtFollowedChannels

View File

@@ -89,7 +89,7 @@ namespace NadekoBot.Modules.Searches
List<FollowedStream> streams = new List<FollowedStream>();
using (var uow = _db.GetDbContext())
{
var all = uow._context
var all = uow
.GuildConfigsForId(ctx.Guild.Id, set => set.Include(gc => gc.FollowedStreams))
.FollowedStreams
.OrderBy(x => x.Id)