/// <summary> /// Deletes RequestViews that remain in database if session ends for user (session is set to 120 min) /// </summary> /// <returns></returns> public async Task DeleteRequestViews() { _logger.LogInformation("Start checking for RequestViews to delete"); List <RequestView> requestViewsToDelete = await _tolkDbContext.RequestViews .Where(rv => rv.ViewedAt < _clock.SwedenNow.AddMinutes(-121)).ToListAsync(); if (requestViewsToDelete.Any()) { try { _tolkDbContext.RemoveRange(requestViewsToDelete); await _tolkDbContext.SaveChangesAsync(); _logger.LogInformation($"{requestViewsToDelete.Count} RequestViews deleted"); return; } catch (Exception ex) { _logger.LogError(ex, "Failing {methodName}", nameof(DeleteRequestViews)); await SendErrorMail(nameof(DeleteRequestViews), ex); } } else { _logger.LogInformation($"No RequestViews to delete"); } }