diff --git a/src/NadekoBot/Db/Extensions/UserXpExtensions.cs b/src/NadekoBot/Db/Extensions/UserXpExtensions.cs index 6fa8f77bb..a808e8329 100644 --- a/src/NadekoBot/Db/Extensions/UserXpExtensions.cs +++ b/src/NadekoBot/Db/Extensions/UserXpExtensions.cs @@ -26,17 +26,6 @@ public static class UserXpExtensions return usr; } - public static async Task> GetUsersFor( - this DbSet xps, - ulong guildId, - int page) - => await xps.ToLinqToDBTable() - .Where(x => x.GuildId == guildId) - .OrderByDescending(x => x.Xp + x.AwardedXp) - .Skip(page * 9) - .Take(9) - .ToArrayAsyncLinqToDB(); - public static async Task> GetTopUserXps(this DbSet xps, ulong guildId, int count) => await xps.ToLinqToDBTable() .Where(x => x.GuildId == guildId) diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index f30697be9..287da1c5c 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -183,27 +183,26 @@ public partial class Xp : NadekoModule await ctx.Channel.TriggerTypingAsync(); - var socketGuild = (SocketGuild)ctx.Guild; - var allCleanUsers = new List(); - if (opts.Clean) - { - await ctx.Channel.TriggerTypingAsync(); - await _tracker.EnsureUsersDownloadedAsync(ctx.Guild); - allCleanUsers = (await _service.GetTopUserXps(ctx.Guild.Id, 1000)) - .Where(user => socketGuild.GetUser(user.UserId) is not null) - .ToList(); + async Task> GetPageItems(int curPage) + { + var socketGuild = (SocketGuild)ctx.Guild; + if (opts.Clean) + { + await ctx.Channel.TriggerTypingAsync(); + await _tracker.EnsureUsersDownloadedAsync(ctx.Guild); + + return await _service.GetTopUserXps(ctx.Guild.Id, + socketGuild.Users.Select(x => x.Id).ToList(), + curPage); + } + + return await _service.GetUserXps(ctx.Guild.Id, curPage); } - var res = opts.Clean - ? Response() + await Response() .Paginated() - .Items(allCleanUsers) - : Response() - .Paginated() - .PageItems((curPage) => _service.GetUserXps(ctx.Guild.Id, curPage)); - - await res + .PageItems(GetPageItems) .PageSize(9) .CurrentPage(page) .Page((users, curPage) => diff --git a/src/NadekoBot/Modules/Xp/XpService.cs b/src/NadekoBot/Modules/Xp/XpService.cs index 81b7d2654..6142800fb 100644 --- a/src/NadekoBot/Modules/Xp/XpService.cs +++ b/src/NadekoBot/Modules/Xp/XpService.cs @@ -12,6 +12,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using System.Threading.Channels; using LinqToDB.EntityFrameworkCore; +using LinqToDB.Tools; using NadekoBot.Modules.Patronage; using Color = SixLabors.ImageSharp.Color; using Exception = System.Exception; @@ -566,13 +567,24 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand public async Task> GetUserXps(ulong guildId, int page) { await using var uow = _db.GetDbContext(); - return await uow.Set().GetUsersFor(guildId, page); + return await uow + .UserXpStats + .Where(x => x.GuildId == guildId) + .OrderByDescending(x => x.Xp + x.AwardedXp) + .Skip(page * 9) + .Take(9) + .ToArrayAsyncLinqToDB(); } - public async Task> GetTopUserXps(ulong guildId, int count) + public async Task> GetTopUserXps(ulong guildId, List users, int curPage) { await using var uow = _db.GetDbContext(); - return await uow.Set().GetTopUserXps(guildId, count); + return await uow.Set() + .Where(x => x.GuildId == guildId && x.UserId.In(users)) + .OrderByDescending(x => x.Xp + x.AwardedXp) + .Skip(curPage * 9) + .Take(9) + .ToArrayAsyncLinqToDB(); } public Task> GetUserXps(int page, int perPage = 9) diff --git a/src/NadekoBot/data/medusae/medusa.yml b/src/NadekoBot/data/medusae/medusa.yml index 89426a9ba..c7b785643 100644 --- a/src/NadekoBot/data/medusae/medusa.yml +++ b/src/NadekoBot/data/medusae/medusa.yml @@ -1,5 +1,4 @@ # DO NOT CHANGE version: 1 # List of medusae automatically loaded at startup -loaded: - - ngrpc +loaded: [] \ No newline at end of file