From 5140a2e741137b3fcfe6e3f181a14314d8cac5e6 Mon Sep 17 00:00:00 2001 From: xiaoxiao921 Date: Mon, 20 Sep 2021 17:28:23 +0200 Subject: [PATCH] only query db if the list is not empty --- CHEF/Components/Commands/Cooking/CookModule.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CHEF/Components/Commands/Cooking/CookModule.cs b/CHEF/Components/Commands/Cooking/CookModule.cs index b58bb25..e4001d0 100644 --- a/CHEF/Components/Commands/Cooking/CookModule.cs +++ b/CHEF/Components/Commands/Cooking/CookModule.cs @@ -68,13 +68,16 @@ private async Task ListRecipesInternal(SocketUser owner = null, int page = 1, st } } - using (var context = new RecipeContext()) + if (badRecipes.Count > 0) { - context.RemoveRange(badRecipes); + using (var context = new RecipeContext()) + { + context.RemoveRange(badRecipes); - await context.SaveChangesAsync(); + await context.SaveChangesAsync(); - Logger.Log($"Removed {badRecipes.Count} bad recipes."); + Logger.Log($"Removed {badRecipes.Count} bad recipes."); + } } if (recipes.Count > 0)