From 1312cc3903d3e277fc883f2672a6bf89d28f7fab Mon Sep 17 00:00:00 2001 From: MarcEricMartel <74071476+MarcEricMartel@users.noreply.github.com> Date: Tue, 25 Oct 2022 10:27:11 -0700 Subject: [PATCH] Update SearchController.cs --- .../GrossesMitainesAPI/Controllers/SearchController.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/SearchController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/SearchController.cs index bf9b019..4153cb4 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/SearchController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/SearchController.cs @@ -22,7 +22,7 @@ public class SearchController : Controller { _logger = logger; _context = context; _cache = cache; - if (_cache.isOk()) + if (_cache.isOk()) // Se fait une copie de la cache si elle est fonctionnelle. _searchCache = _cache.GetCacheCopy(); } @@ -61,10 +61,10 @@ public class SearchController : Controller { products.AddRange(cat); } else { products = _context.Products.Where(x => x.Title.Contains(query)).ToList(); - foreach (Product prod in _context.Products.Where(x => x.Description.Contains(query)).ToList()) + foreach (Product prod in _context.Products.Where(x => x.Description.Contains(query)).ToArray()) if (!products.Contains(prod)) products.Add(prod); - foreach (Product prod in _context.Products.Where(x => x.Category.Contains(query)).ToList()) + foreach (Product prod in _context.Products.Where(x => x.Category.Contains(query)).ToArray()) if (!products.Contains(prod)) products.Add(prod); } @@ -80,7 +80,7 @@ public class SearchController : Controller { query = query.Trim(); if (_searchCache is null) { _logger.LogError(8, "Erreur de cache."); - return Search(query, preview, deep); // Fallback vers version non-cached. + return Search(query, preview, deep); // Fallback vers version non-cached en cas d'erreur. } try { // Pour faire une liste priorisée. if (preview.HasValue && preview == true) @@ -117,7 +117,7 @@ public class SearchController : Controller { } } catch (Exception e) { _logger.LogError(8, e.Message); - return Search(query, preview, deep); // Fallback vers version non-cached. + return Search(query, preview, deep); // Fallback vers version non-cached en cas d'erreur. } return products; }