diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 093234e99..913472648 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -90,16 +90,16 @@ public sealed class Bot : IBot public IReadOnlyList GetCurrentGuildIds() => Client.Guilds.Select(x => x.Id).ToList().AsReadOnly(); - private void AddServices() + private async Task AddServices() { var startingGuildIdList = GetCurrentGuildIds(); var startTime = Stopwatch.GetTimestamp(); var bot = Client.CurrentUser; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { uow.EnsureUserCreated(bot.Id, bot.Username, bot.Discriminator, bot.AvatarId); - AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList); + AllGuildConfigs = await uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList); } // var svcs = new StandardKernel(new NinjectSettings() @@ -265,7 +265,7 @@ public sealed class Bot : IBot Log.Information("Shard {ShardId} loading services...", Client.ShardId); try { - AddServices(); + await AddServices(); } catch (Exception ex) { diff --git a/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs b/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs index f82425db2..ee87a18f8 100644 --- a/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs +++ b/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs @@ -1,4 +1,5 @@ #nullable disable +using LinqToDB.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using NadekoBot.Db.Models; @@ -42,7 +43,7 @@ public static class GuildConfigExtensions } private static IQueryable IncludeEverything(this DbSet configs) - => configs.AsQueryable() + => configs .AsSplitQuery() .Include(gc => gc.CommandCooldowns) .Include(gc => gc.FollowedStreams) @@ -52,14 +53,13 @@ public static class GuildConfigExtensions .ThenInclude(x => x.ExclusionList) ; - public static IReadOnlyCollection GetAllGuildConfigs( + public static Task GetAllGuildConfigs( this DbSet configs, IReadOnlyList availableGuilds) => configs.IncludeEverything() .Where(x => availableGuilds.Contains(x.GuildId)) .AsNoTracking() - .ToList() - .AsReadOnly(); + .ToArrayAsyncEF(); /// /// Gets and creates if it doesn't exist a config for a guild.