Skip to content

Commit

Permalink
Merge pull request #1538 from qdraw/feature/202404_mysql-search-sugge…
Browse files Browse the repository at this point in the history
…st-exception-catch-ed

$"[SearchSuggestionsService] exception catch-ed {exception.Message} {…
  • Loading branch information
qdraw authored Apr 8, 2024
2 parents 90fb9c6 + feb1a44 commit 77fedf8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions starsky/starsky.feature.search/Services/SearchSuggestionsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace starsky.feature.search.Services
{

[Service(typeof(ISearchSuggest), InjectionLifetime = InjectionLifetime.Scoped)]
public class SearchSuggestionsService : ISearchSuggest
{
Expand Down Expand Up @@ -42,8 +41,10 @@ public SearchSuggestionsService(
/// All keywords are stored lowercase
/// </summary>
/// <returns></returns>
[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<List<KeyValuePair<string, int>>> Inflate()
{
Expand All @@ -68,12 +69,15 @@ public async Task<List<KeyValuePair<string, int>>> 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<string, int>(StringComparer.InvariantCultureIgnoreCase);
var suggestions =
new Dictionary<string, int>(StringComparer.InvariantCultureIgnoreCase);

foreach ( var tag in allFilesList )
{
Expand All @@ -99,8 +103,9 @@ public async Task<List<KeyValuePair<string, int>>> 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);
Expand All @@ -118,9 +123,10 @@ public async Task<IEnumerable<KeyValuePair<string, int>>> GetAllSuggestions()
return new Dictionary<string, int>();

if ( _cache.TryGetValue(nameof(SearchSuggestionsService),
out var objectFileFolders) )
out var objectFileFolders) )
{
return objectFileFolders as List<KeyValuePair<string, int>> ?? new List<KeyValuePair<string, int>>();
return objectFileFolders as List<KeyValuePair<string, int>> ??
new List<KeyValuePair<string, int>>();
}

return await Inflate();
Expand Down Expand Up @@ -172,6 +178,5 @@ private static IEnumerable<string> SystemResults()
"-isDirectory:false"
];
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

}
Expand Down

0 comments on commit 77fedf8

Please sign in to comment.