mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 02:08:27 -04:00
UnitOfWork compltely removed. GetDbContext now returns a NadekoContext. Changed every access to contect via uow._context to uow
This commit is contained in:
@@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||
var configs = uow._context.Set<GuildConfig>()
|
||||
var configs = uow.Set<GuildConfig>()
|
||||
.Include(gc => gc.CommandAliases)
|
||||
.Where(x => guildIds.Contains(x.GuildId))
|
||||
.ToList();
|
||||
@@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
int count;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.CommandAliases));
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.CommandAliases));
|
||||
count = gc.CommandAliases.Count;
|
||||
gc.CommandAliases.Clear();
|
||||
uow.SaveChanges();
|
||||
|
@@ -138,7 +138,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var users = uow._context.Set<RewardedUser>();
|
||||
var users = uow.Set<RewardedUser>();
|
||||
var usr = users.FirstOrDefault(x => x.PatreonUserId == data.User.id);
|
||||
|
||||
if (usr == null)
|
||||
|
@@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow._context.Set<Reminder>()
|
||||
uow.Set<Reminder>()
|
||||
.RemoveRange(reminders);
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
@@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
return uow._context.Reminders
|
||||
return uow.Reminders
|
||||
.FromSqlInterpolated($"select * from reminders where ((serverid >> 22) % {_creds.TotalShards}) == {_client.ShardId} and \"when\" < {now};")
|
||||
.ToListAsync();
|
||||
}
|
||||
|
@@ -40,8 +40,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
_client = client;
|
||||
|
||||
var uow = _db.GetDbContext();
|
||||
var shardRepeaters = uow
|
||||
._context
|
||||
var shardRepeaters = uow
|
||||
.Set<Repeater>()
|
||||
.FromSqlInterpolated($@"select * from repeaters
|
||||
where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
@@ -133,7 +132,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
|
||||
var toTrigger = await uow._context.Repeaters
|
||||
var toTrigger = await uow.Repeaters
|
||||
.AsNoTracking()
|
||||
.Skip(index)
|
||||
.FirstOrDefaultAsyncEF(x => x.GuildId == guildId);
|
||||
@@ -290,7 +289,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
_noRedundant.TryRemove(r.Id);
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
await uow._context
|
||||
await uow
|
||||
.Repeaters
|
||||
.DeleteAsync(x => x.Id == r.Id);
|
||||
|
||||
@@ -313,7 +312,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
private async Task SetRepeaterLastMessageInternal(int repeaterId, ulong lastMsgId)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
await uow._context.Repeaters
|
||||
await uow.Repeaters
|
||||
.AsQueryable()
|
||||
.Where(x => x.Id == repeaterId)
|
||||
.UpdateAsync(rep => new Repeater()
|
||||
@@ -345,8 +344,8 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
|
||||
if (await uow._context.Repeaters.AsNoTracking().CountAsyncEF() < MAX_REPEATERS)
|
||||
uow._context.Repeaters.Add(rep);
|
||||
if (await uow.Repeaters.AsNoTracking().CountAsyncEF() < MAX_REPEATERS)
|
||||
uow.Repeaters.Add(rep);
|
||||
else
|
||||
return null;
|
||||
|
||||
@@ -365,7 +364,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
using var uow = _db.GetDbContext();
|
||||
var toRemove = await uow._context.Repeaters
|
||||
var toRemove = await uow.Repeaters
|
||||
.AsNoTracking()
|
||||
.Skip(index)
|
||||
.FirstOrDefaultAsyncEF(x => x.GuildId == guildId);
|
||||
@@ -380,7 +379,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
return null;
|
||||
|
||||
_noRedundant.TryRemove(toRemove.Id);
|
||||
uow._context.Repeaters.Remove(toRemove);
|
||||
uow.Repeaters.Remove(toRemove);
|
||||
await uow.SaveChangesAsync();
|
||||
return removed;
|
||||
}
|
||||
@@ -396,7 +395,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
|
||||
public async Task<bool?> ToggleRedundantAsync(ulong guildId, int index)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var toToggle = await uow._context
|
||||
var toToggle = await uow
|
||||
.Repeaters
|
||||
.AsQueryable()
|
||||
.Skip(index)
|
||||
|
@@ -81,7 +81,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
bool success = false;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id);
|
||||
var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
|
||||
|
||||
if (listType == StreamRoleListType.Whitelist)
|
||||
{
|
||||
@@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
var toDelete = streamRoleSettings.Whitelist.FirstOrDefault(x => x.Equals(userObj));
|
||||
if (toDelete != null)
|
||||
{
|
||||
uow._context.Remove(toDelete);
|
||||
uow.Remove(toDelete);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id);
|
||||
var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
|
||||
|
||||
streamRoleSettings.Keyword = keyword;
|
||||
UpdateCache(guild.Id, streamRoleSettings);
|
||||
@@ -170,7 +170,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
StreamRoleSettings setting;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
setting = uow._context.GetStreamRoleSettings(guildId);
|
||||
setting = uow.GetStreamRoleSettings(guildId);
|
||||
}
|
||||
|
||||
UpdateCache(guildId, setting);
|
||||
@@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
StreamRoleSettings setting;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var streamRoleSettings = uow._context.GetStreamRoleSettings(fromRole.Guild.Id);
|
||||
var streamRoleSettings = uow.GetStreamRoleSettings(fromRole.Guild.Id);
|
||||
|
||||
streamRoleSettings.Enabled = true;
|
||||
streamRoleSettings.AddRoleId = addRole.Id;
|
||||
@@ -219,7 +219,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id);
|
||||
var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
|
||||
streamRoleSettings.Enabled = false;
|
||||
streamRoleSettings.AddRoleId = 0;
|
||||
streamRoleSettings.FromRoleId = 0;
|
||||
|
@@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var gc = uow._context.GuildConfigsForId(guildId, set => set);
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
|
||||
if (enabled==null) enabled = gc.VerboseErrors = !gc.VerboseErrors; // Old behaviour, now behind a condition
|
||||
else gc.VerboseErrors = (bool)enabled; // New behaviour, just set it.
|
||||
|
Reference in New Issue
Block a user