diff --git a/src/NadekoBot/Db/Extensions/WaifuExtensions.cs b/src/NadekoBot/Db/Extensions/WaifuExtensions.cs index 266708768..fabdd83b6 100644 --- a/src/NadekoBot/Db/Extensions/WaifuExtensions.cs +++ b/src/NadekoBot/Db/Extensions/WaifuExtensions.cs @@ -18,8 +18,8 @@ public class WaifuInfoStats public int DivorceCount { get; init; } public int ClaimCount { get; init; } public List Items { get; init; } - public List Claims { get; init; } - public List Fans { get; init; } + public List Claims { get; init; } + public List Fans { get; init; } } public static class WaifuExtensions @@ -134,17 +134,19 @@ public static class WaifuExtensions .Count(x => x.OldId == w.WaifuId && x.NewId == null && x.UpdateType == WaifuUpdateType.Claimed), + Price = w.Price, - Claims = ctx.WaifuInfo.AsQueryable() - .Include(x => x.Waifu) + + Claims = ctx.WaifuInfo .Where(x => x.ClaimerId == w.WaifuId) - .Select(x => x.Waifu.Username + "#" + x.Waifu.Discriminator) + .Select(x => x.WaifuId) .ToList(), - Fans = ctx.WaifuInfo.AsQueryable() - .Include(x => x.Waifu) + + Fans = ctx.WaifuInfo .Where(x => x.AffinityId == w.WaifuId) - .Select(x => x.Waifu.Username + "#" + x.Waifu.Discriminator) + .Select(x => x.WaifuId) .ToList(), + Items = w.Items }) .FirstOrDefault(); diff --git a/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs b/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs index 8e5382549..7b65d337b 100644 --- a/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs +++ b/src/NadekoBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs @@ -244,7 +244,6 @@ public partial class Gambling var waifuItems = _service.GetWaifuItems().ToDictionary(x => x.ItemEmoji, x => x); - var nobody = GetText(strs.nobody); var itemsStr = !wi.Items.Any() ? "-" @@ -256,7 +255,17 @@ public partial class Gambling .Chunk(2) .Select(x => string.Join(" ", x))); - var fansStr = wi.Fans.Shuffle().Take(30).Select(x => wi.Claims.Contains(x) ? $"{x} 💞" : x).Join('\n'); + var claimsNames = (await _service.GetBulkWaifuNames(wi.Claims)); + var claimsStr = claimsNames + .Shuffle() + .Take(30) + .Join('\n'); + + var fansStr = (await _service.GetBulkWaifuNames(wi.Fans + .Shuffle() + .Take(30))) + .Select((x) => claimsNames.Contains(x) ? $"{x} 💞" : x).Join('\n'); + if (string.IsNullOrWhiteSpace(fansStr)) fansStr = "-"; @@ -277,7 +286,7 @@ public partial class Gambling .AddField("\u200B", "\u200B", true) .AddField(GetText(strs.fans(wi.Fans.Count)), fansStr, true) .AddField($"Waifus ({wi.ClaimCount})", - wi.ClaimCount == 0 ? nobody : string.Join("\n", wi.Claims.Shuffle().Take(30)), + wi.ClaimCount == 0 ? nobody : claimsStr, true) .AddField(GetText(strs.gifts), itemsStr, true); diff --git a/src/NadekoBot/Modules/Gambling/Waifus/WaifuService.cs b/src/NadekoBot/Modules/Gambling/Waifus/WaifuService.cs index 539a01cac..6604ad8ee 100644 --- a/src/NadekoBot/Modules/Gambling/Waifus/WaifuService.cs +++ b/src/NadekoBot/Modules/Gambling/Waifus/WaifuService.cs @@ -557,4 +557,13 @@ public class WaifuService : INService, IReadyExecutor } } } + + public async Task> GetBulkWaifuNames(IEnumerable take) + { + await using var ctx = _db.GetDbContext(); + return await ctx.GetTable() + .Where(x => take.Contains(x.Id)) + .Select(x => $"{x.Username}#{x.Discriminator}") + .ToListAsyncLinqToDB(); + } } \ No newline at end of file