some more cleanup/attempts to fix a weird mysql error

Also updated .gitignore to ignore ellie-menu.ps1 and updated the script link in EllieBot.sln
This commit is contained in:
Toastie (DCS Team) 2024-09-09 14:04:08 +12:00
parent f15d1d2495
commit 140a35b82a
No known key found for this signature in database
4 changed files with 10 additions and 9 deletions

1
.gitignore vendored
View file

@ -20,6 +20,7 @@ src/EllieBot/credentials.json
src/EllieBot/old_credentials.json src/EllieBot/old_credentials.json
src/EllieBot/credentials.json.bak src/EllieBot/credentials.json.bak
src/EllieBot/data/EllieBot.db src/EllieBot/data/EllieBot.db
ellie-menu.ps1
# Created by https://www.gitignore.io/api/visualstudio,visualstudiocode,windows,linux,macos # Created by https://www.gitignore.io/api/visualstudio,visualstudiocode,windows,linux,macos

View file

@ -7,9 +7,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B28FB883-968
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6C633450-E6C2-47ED-A7AA-7367232F703A}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6C633450-E6C2-47ED-A7AA-7367232F703A}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
build.ps1 = build.ps1
CHANGELOG.md = CHANGELOG.md CHANGELOG.md = CHANGELOG.md
Dockerfile = Dockerfile Dockerfile = Dockerfile
ellie-menu.ps1 = ellie-menu.ps1
LICENSE = LICENSE LICENSE = LICENSE
migrate.ps1 = migrate.ps1 migrate.ps1 = migrate.ps1
README.md = README.md README.md = README.md

View file

@ -90,16 +90,16 @@ public sealed class Bot : IBot
public IReadOnlyList<ulong> GetCurrentGuildIds() public IReadOnlyList<ulong> GetCurrentGuildIds()
=> Client.Guilds.Select(x => x.Id).ToList().AsReadOnly(); => Client.Guilds.Select(x => x.Id).ToList().AsReadOnly();
private void AddServices() private async Task AddServices()
{ {
var startingGuildIdList = GetCurrentGuildIds(); var startingGuildIdList = GetCurrentGuildIds();
var startTime = Stopwatch.GetTimestamp(); var startTime = Stopwatch.GetTimestamp();
var bot = Client.CurrentUser; 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); 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() // var svcs = new StandardKernel(new NinjectSettings()
@ -265,7 +265,7 @@ public sealed class Bot : IBot
Log.Information("Shard {ShardId} loading services...", Client.ShardId); Log.Information("Shard {ShardId} loading services...", Client.ShardId);
try try
{ {
AddServices(); await AddServices();
} }
catch (Exception ex) catch (Exception ex)
{ {

View file

@ -1,5 +1,6 @@
#nullable disable #nullable disable
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using LinqToDB.EntityFrameworkCore;
using EllieBot.Db.Models; using EllieBot.Db.Models;
namespace EllieBot.Db; namespace EllieBot.Db;
@ -42,7 +43,7 @@ public static class GuildConfigExtensions
} }
private static IQueryable<GuildConfig> IncludeEverything(this DbSet<GuildConfig> configs) private static IQueryable<GuildConfig> IncludeEverything(this DbSet<GuildConfig> configs)
=> configs.AsQueryable() => configs
.AsSplitQuery() .AsSplitQuery()
.Include(gc => gc.CommandCooldowns) .Include(gc => gc.CommandCooldowns)
.Include(gc => gc.FollowedStreams) .Include(gc => gc.FollowedStreams)
@ -51,14 +52,13 @@ public static class GuildConfigExtensions
.Include(gc => gc.XpSettings) .Include(gc => gc.XpSettings)
.ThenInclude(x => x.ExclusionList); .ThenInclude(x => x.ExclusionList);
public static IReadOnlyCollection<GuildConfig> GetAllGuildConfigs( public static Task<GuildConfig[]> GetAllGuildConfigs(
this DbSet<GuildConfig> configs, this DbSet<GuildConfig> configs,
IReadOnlyList<ulong> availableGuilds) IReadOnlyList<ulong> availableGuilds)
=> configs.IncludeEverything() => configs.IncludeEverything()
.AsNoTracking() .AsNoTracking()
.Where(x => availableGuilds.Contains(x.GuildId)) .Where(x => availableGuilds.Contains(x.GuildId))
.ToList() .ToArrayAsyncEF();
.AsReadOnly();
/// <summary> /// <summary>
/// Gets and creates if it doesn't exist a config for a guild. /// Gets and creates if it doesn't exist a config for a guild.