diff --git a/starsky/starsky.feature.search/Services/SearchSuggestionsService.cs b/starsky/starsky.feature.search/Services/SearchSuggestionsService.cs index d4f4f38550..cd2d32d066 100644 --- a/starsky/starsky.feature.search/Services/SearchSuggestionsService.cs +++ b/starsky/starsky.feature.search/Services/SearchSuggestionsService.cs @@ -14,7 +14,6 @@ namespace starsky.feature.search.Services { - [Service(typeof(ISearchSuggest), InjectionLifetime = InjectionLifetime.Scoped)] public class SearchSuggestionsService : ISearchSuggest { @@ -42,8 +41,10 @@ public SearchSuggestionsService( /// All keywords are stored lowercase /// /// - [SuppressMessage("Performance", "CA1827:Do not use Count() or LongCount() when Any() can be used")] - [SuppressMessage("Performance", "S1155:Do not use Count() or LongCount() when Any() can be used", + [SuppressMessage("Performance", + "CA1827:Do not use Count() or LongCount() when Any() can be used")] + [SuppressMessage("Performance", + "S1155:Do not use Count() or LongCount() when Any() can be used", Justification = "ANY is not supported by EF Core")] public async Task>> Inflate() { @@ -68,12 +69,15 @@ public async Task>> Inflate() { if ( !exception.Message.Contains("Unknown column") ) { - _logger.LogError(exception, "mysql search suggest exception catch-ed"); + _logger.LogError(exception, + $"[SearchSuggestionsService] exception catch-ed {exception.Message} {exception.StackTrace}"); } + return allFilesList; } - var suggestions = new Dictionary(StringComparer.InvariantCultureIgnoreCase); + var suggestions = + new Dictionary(StringComparer.InvariantCultureIgnoreCase); foreach ( var tag in allFilesList ) { @@ -99,8 +103,9 @@ public async Task>> Inflate() .OrderByDescending(p => p.Value) .ToList(); - var cacheExpire = suggestionsFiltered.Count != 0 ? - new TimeSpan(120, 0, 0) : new TimeSpan(0, 1, 0); + var cacheExpire = suggestionsFiltered.Count != 0 + ? new TimeSpan(120, 0, 0) + : new TimeSpan(0, 1, 0); _cache.Set(nameof(SearchSuggestionsService), suggestionsFiltered, cacheExpire); @@ -118,9 +123,10 @@ public async Task>> GetAllSuggestions() return new Dictionary(); if ( _cache.TryGetValue(nameof(SearchSuggestionsService), - out var objectFileFolders) ) + out var objectFileFolders) ) { - return objectFileFolders as List> ?? new List>(); + return objectFileFolders as List> ?? + new List>(); } return await Inflate(); @@ -172,6 +178,5 @@ private static IEnumerable SystemResults() "-isDirectory:false" ]; } - } } diff --git a/starsky/starskytest/starsky.foundation.search/Services/SearchSuggestionsServiceTest.cs b/starsky/starskytest/starsky.foundation.search/Services/SearchSuggestionsServiceTest.cs index dd59eeae50..bea45658dd 100644 --- a/starsky/starskytest/starsky.foundation.search/Services/SearchSuggestionsServiceTest.cs +++ b/starsky/starskytest/starsky.foundation.search/Services/SearchSuggestionsServiceTest.cs @@ -140,7 +140,7 @@ public async Task SearchSuggestionsService_MySqlError() await suggest.Inflate(); - Assert.AreEqual("mysql search suggest exception catch-ed", fakeLogger.TrackedExceptions.LastOrDefault().Item2); + Assert.IsTrue(fakeLogger.TrackedExceptions.LastOrDefault().Item2?.Contains("[SearchSuggestionsService] exception catch-ed")); } }