Skip to content

Commit

Permalink
perf: ⚡ implement CancellationToken properly (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed Jul 3, 2023
1 parent db57ff6 commit 9c88afa
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 74 deletions.
10 changes: 5 additions & 5 deletions src/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ await Task.Run(() =>
{
_ = Task.Run(async () =>
{
if (!await this._togglTrack!.VerifyApiToken())
if (!await this._togglTrack!.VerifyApiToken(CancellationToken.None))
{
return;
}
Expand All @@ -72,20 +72,20 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
{
return this._togglTrack!.NotifyNetworkUnavailable();
}
else if (!await this._togglTrack!.VerifyApiToken())
else if (!await this._togglTrack!.VerifyApiToken(token))
{
return this._togglTrack.NotifyInvalidToken();
}

if (string.IsNullOrWhiteSpace(query.Search))
{
return await this._togglTrack.GetDefaultHotKeys(prefetch: true);
return await this._togglTrack.GetDefaultHotKeys(token, prefetch: true);
}

string command = query.FirstSearch;
if (!Settings.Commands.Contains(command) && command == this._state.LastCommand)
{
command = (await this._togglTrack.GetDefaultHotKeys())
command = (await this._togglTrack.GetDefaultHotKeys(token))
.GroupBy(result => this._context!.API.FuzzySearch(query.FirstSearch, result.Title).Score)
.MaxBy(group => group.Key)
?.MaxBy(result => result.Score)
Expand All @@ -103,7 +103,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
Settings.EditCommand => await this._togglTrack.RequestEditEntry(token, query),
Settings.DeleteCommand => await this._togglTrack.RequestDeleteEntry(token, query),
Settings.ReportsCommand => await this._togglTrack.RequestViewReports(token, query),
_ => (await this._togglTrack.GetDefaultHotKeys())
_ => (await this._togglTrack.GetDefaultHotKeys(token))
.FindAll(result =>
{
return this._context!.API.FuzzySearch(query.Search, result.Title).Score > 0;
Expand Down
Loading

0 comments on commit 9c88afa

Please sign in to comment.