mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Possible optimization for .waifuinfo
This commit is contained in:
@@ -18,8 +18,8 @@ public class WaifuInfoStats
|
|||||||
public int DivorceCount { get; init; }
|
public int DivorceCount { get; init; }
|
||||||
public int ClaimCount { get; init; }
|
public int ClaimCount { get; init; }
|
||||||
public List<WaifuItem> Items { get; init; }
|
public List<WaifuItem> Items { get; init; }
|
||||||
public List<string> Claims { get; init; }
|
public List<int> Claims { get; init; }
|
||||||
public List<string> Fans { get; init; }
|
public List<int> Fans { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class WaifuExtensions
|
public static class WaifuExtensions
|
||||||
@@ -134,17 +134,19 @@ public static class WaifuExtensions
|
|||||||
.Count(x => x.OldId == w.WaifuId
|
.Count(x => x.OldId == w.WaifuId
|
||||||
&& x.NewId == null
|
&& x.NewId == null
|
||||||
&& x.UpdateType == WaifuUpdateType.Claimed),
|
&& x.UpdateType == WaifuUpdateType.Claimed),
|
||||||
|
|
||||||
Price = w.Price,
|
Price = w.Price,
|
||||||
Claims = ctx.WaifuInfo.AsQueryable()
|
|
||||||
.Include(x => x.Waifu)
|
Claims = ctx.WaifuInfo
|
||||||
.Where(x => x.ClaimerId == w.WaifuId)
|
.Where(x => x.ClaimerId == w.WaifuId)
|
||||||
.Select(x => x.Waifu.Username + "#" + x.Waifu.Discriminator)
|
.Select(x => x.WaifuId)
|
||||||
.ToList(),
|
.ToList(),
|
||||||
Fans = ctx.WaifuInfo.AsQueryable()
|
|
||||||
.Include(x => x.Waifu)
|
Fans = ctx.WaifuInfo
|
||||||
.Where(x => x.AffinityId == w.WaifuId)
|
.Where(x => x.AffinityId == w.WaifuId)
|
||||||
.Select(x => x.Waifu.Username + "#" + x.Waifu.Discriminator)
|
.Select(x => x.WaifuId)
|
||||||
.ToList(),
|
.ToList(),
|
||||||
|
|
||||||
Items = w.Items
|
Items = w.Items
|
||||||
})
|
})
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
@@ -244,7 +244,6 @@ public partial class Gambling
|
|||||||
|
|
||||||
var waifuItems = _service.GetWaifuItems().ToDictionary(x => x.ItemEmoji, x => x);
|
var waifuItems = _service.GetWaifuItems().ToDictionary(x => x.ItemEmoji, x => x);
|
||||||
|
|
||||||
|
|
||||||
var nobody = GetText(strs.nobody);
|
var nobody = GetText(strs.nobody);
|
||||||
var itemsStr = !wi.Items.Any()
|
var itemsStr = !wi.Items.Any()
|
||||||
? "-"
|
? "-"
|
||||||
@@ -256,7 +255,17 @@ public partial class Gambling
|
|||||||
.Chunk(2)
|
.Chunk(2)
|
||||||
.Select(x => string.Join(" ", x)));
|
.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))
|
if (string.IsNullOrWhiteSpace(fansStr))
|
||||||
fansStr = "-";
|
fansStr = "-";
|
||||||
@@ -277,7 +286,7 @@ public partial class Gambling
|
|||||||
.AddField("\u200B", "\u200B", true)
|
.AddField("\u200B", "\u200B", true)
|
||||||
.AddField(GetText(strs.fans(wi.Fans.Count)), fansStr, true)
|
.AddField(GetText(strs.fans(wi.Fans.Count)), fansStr, true)
|
||||||
.AddField($"Waifus ({wi.ClaimCount})",
|
.AddField($"Waifus ({wi.ClaimCount})",
|
||||||
wi.ClaimCount == 0 ? nobody : string.Join("\n", wi.Claims.Shuffle().Take(30)),
|
wi.ClaimCount == 0 ? nobody : claimsStr,
|
||||||
true)
|
true)
|
||||||
.AddField(GetText(strs.gifts), itemsStr, true);
|
.AddField(GetText(strs.gifts), itemsStr, true);
|
||||||
|
|
||||||
|
@@ -557,4 +557,13 @@ public class WaifuService : INService, IReadyExecutor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IReadOnlyCollection<string>> GetBulkWaifuNames(IEnumerable<int> take)
|
||||||
|
{
|
||||||
|
await using var ctx = _db.GetDbContext();
|
||||||
|
return await ctx.GetTable<DiscordUser>()
|
||||||
|
.Where(x => take.Contains(x.Id))
|
||||||
|
.Select(x => $"{x.Username}#{x.Discriminator}")
|
||||||
|
.ToListAsyncLinqToDB();
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user