Skip to content

Commit

Permalink
$"[SearchSuggestionsService] exception catch-ed {exception.Message} {…
Browse files Browse the repository at this point in the history
…exception.StackTrace}");
  • Loading branch information
qdraw committed Apr 8, 2024
1 parent 90fb9c6 commit 7b637b5
Showing 1 changed file with 15 additions and 10 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"
];
}

}
}

0 comments on commit 7b637b5

Please sign in to comment.