From 81a02c6e64ed67825b547d64393b83911cefdf08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Tue, 24 Nov 2020 17:38:24 +0800 Subject: [PATCH] Don't add result to queue unless the query match (plugin event driven update) Remove the Task.Run because updating result metadata and adding result to queue should not be time wasted. --- Flow.Launcher/ViewModel/MainViewModel.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 3d3792c54..f398df92b 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -96,11 +96,9 @@ namespace Flow.Launcher.ViewModel var plugin = (IResultUpdated)pair.Plugin; plugin.ResultsUpdated += (s, e) => { - Task.Run(async () => - { - PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query); - await _resultsUpdateQueue.SendAsync(new ResultsForUpdate(e.Results, pair.Metadata, e.Query, _updateToken)); - }, _updateToken); + PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query); + if (e.Query.Search == _lastQuery.Search) + _resultsUpdateQueue.Post(new ResultsForUpdate(e.Results, pair.Metadata, e.Query, _updateToken)); }; } } @@ -428,13 +426,13 @@ namespace Flow.Launcher.ViewModel { // Wait 45 millisecond for query change in global query // if query changes, return so that it won't be calculated - await Task.Delay(45); + await Task.Delay(45, currentCancellationToken); if (!(_lastQuery.Search == query.Search)) return; } _ = Task.Delay(200, currentCancellationToken).ContinueWith(_ => - { + { // start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet if (currentUpdateSource == _updateSource && _isQueryRunning) {