public async Task <IActionResult> GetCardsAsync([FromBody] GetCardsRequest request) { try { if (request.ExcludedCardIds == null) { throw new ArgumentException("request.ExcludedCardIds is null"); } if (request.ExcludedTagIds == null) { throw new ArgumentException("request.ExcludedTagIds is null"); } var currentUserId = await UserServices.UserIdFromContextAsync(HttpContext, userManager); var cardsToDownload = request.CurrentCardCount == 0 ? 1 : (request.LearnModeIsUnknown ? 30 : 5); //loading cards to repeat is much more time consuming var applicationRequest = new GetCardsToLearn.Request(currentUserId, request.DeckId, request.LearnModeIsUnknown, request.ExcludedCardIds, request.ExcludedTagIds, cardsToDownload); var applicationResult = await new GetCardsToLearn(dbContext).RunAsync(applicationRequest); var user = await userManager.GetUserAsync(HttpContext.User); var result = new GetCardsViewModel(applicationResult, localizer, user.UserName); return(Ok(result)); } catch (Exception e) { return(ControllerError.BadRequest(e, this)); } }
async public Task RunAsync(MemCheckDbContext dbContext) { var user = dbContext.Users.Where(user => user.UserName == "Voltan").Single(); var deck = dbContext.Decks.Where(deck => deck.Owner == user).First(); if (realCode) { var chronos = new List <double>(); for (int i = 0; i < 5; i++) { var realCodeChrono = Stopwatch.StartNew(); var request = new GetCardsToLearn.Request(user.Id, deck.Id, false, new Guid[0], new Guid[0], 30); var runner = new GetCardsToLearn(dbContext); var cards = await runner.RunAsync(request); logger.LogInformation($"Got {cards.Count()} in {realCodeChrono.Elapsed}"); chronos.Add(realCodeChrono.Elapsed.TotalSeconds); } logger.LogInformation($"Average time: {chronos.Average()} seconds"); } else { var chrono = Stopwatch.StartNew(); var logLines = await GetCardsToRepeatAsync(user.Id, deck.Id, new Guid[0], new Guid[0]); chrono.Stop(); foreach (var logLine in logLines) { logger.LogInformation(logLine); } logger.LogInformation($"Ran in {chrono.Elapsed}"); } }