.curtrs may? run a little faster. Uses async, clarified GamblingConfig transactionLifetime field

This commit is contained in:
Kwoth
2022-09-28 07:09:37 +02:00
parent a8e06a5ae4
commit a5b2fac69c
3 changed files with 13 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
#nullable disable #nullable disable
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
@@ -6,12 +7,14 @@ namespace NadekoBot.Db;
public static class CurrencyTransactionExtensions public static class CurrencyTransactionExtensions
{ {
public static List<CurrencyTransaction> GetPageFor(this DbSet<CurrencyTransaction> set, ulong userId, int page) public static Task<List<CurrencyTransaction>> GetPageFor(
=> set.AsQueryable() this DbSet<CurrencyTransaction> set,
.AsNoTracking() ulong userId,
int page)
=> set.ToLinqToDBTable()
.Where(x => x.UserId == userId) .Where(x => x.UserId == userId)
.OrderByDescending(x => x.DateAdded) .OrderByDescending(x => x.DateAdded)
.Skip(15 * page) .Skip(15 * page)
.Take(15) .Take(15)
.ToList(); .ToListAsyncLinqToDB();
} }

View File

@@ -249,7 +249,7 @@ public partial class Gambling : GamblingModule<GamblingService>
List<CurrencyTransaction> trs; List<CurrencyTransaction> trs;
await using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
trs = uow.CurrencyTransactions.GetPageFor(userId, page); trs = await uow.CurrencyTransactions.GetPageFor(userId, page);
} }
var embed = _eb.Create() var embed = _eb.Create()

View File

@@ -78,7 +78,7 @@ public class CurrencyConfig
[Comment(@"What is the name of the currency")] [Comment(@"What is the name of the currency")]
public string Name { get; set; } = "Nadeko Flower"; public string Name { get; set; } = "Nadeko Flower";
[Comment(@"For how long will the transactions be kept in the database (curtrs) [Comment(@"For how long (in days) will the transactions be kept in the database (curtrs)
Set 0 to disable cleanup (keep transactions forever)")] Set 0 to disable cleanup (keep transactions forever)")]
public int TransactionsLifetime { get; set; } = 0; public int TransactionsLifetime { get; set; } = 0;
} }