Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$"[SearchSuggestionsService] exception catch-ed {exception.Message} {… #1538

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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