Remove a database call from !quote by delegating the randomness to the database.
This commit is contained in:
parent
1b9d8732d5
commit
447c6d8042
1 changed files with 5 additions and 10 deletions
|
@ -45,22 +45,17 @@ namespace Geekbot.Bot.Commands.Utils.Quote
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var getTotalSpan = Transaction.StartChild("TotalQuotes");
|
var getQuoteFromDbSpan = Transaction.StartChild("GetQuoteFromDB");
|
||||||
var totalQuotes = await _database.Quotes.CountAsync(e => e.GuildId.Equals(Context.Guild.Id.AsLong()));
|
var quote = _database.Quotes.FromSqlInterpolated($"select * from \"Quotes\" where \"GuildId\" = {Context.Guild.Id} order by random() limit 1");
|
||||||
getTotalSpan.Finish();
|
getQuoteFromDbSpan.Finish();
|
||||||
|
|
||||||
if (totalQuotes == 0)
|
if (!quote.Any())
|
||||||
{
|
{
|
||||||
await ReplyAsync(Localization.Quote.NoQuotesFound);
|
await ReplyAsync(Localization.Quote.NoQuotesFound);
|
||||||
Transaction.Status = SpanStatus.NotFound;
|
Transaction.Status = SpanStatus.NotFound;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var getQuoteFromDbSpan = Transaction.StartChild("GetQuoteFromDB");
|
|
||||||
var random = _randomNumberGenerator.Next(0, totalQuotes - 1);
|
|
||||||
var quote = _database.Quotes.Where(e => e.GuildId.Equals(Context.Guild.Id.AsLong())).Skip(random).Take(1);
|
|
||||||
getQuoteFromDbSpan.Finish();
|
|
||||||
|
|
||||||
var buildQuoteEmbedSpan = Transaction.StartChild("BuildQuoteEmbed");
|
var buildQuoteEmbedSpan = Transaction.StartChild("BuildQuoteEmbed");
|
||||||
var embed = QuoteBuilder(quote.FirstOrDefault());
|
var embed = QuoteBuilder(quote.FirstOrDefault());
|
||||||
buildQuoteEmbedSpan.Finish();
|
buildQuoteEmbedSpan.Finish();
|
||||||
|
|
Loading…
Reference in a new issue