[PTRun]Fix cutting off and using previous input (#19215)

* Deselect previous selected item because it might not be valid.

* fast execute non-delayed queries

* Speling fixxes.

* Fixed _isTextSetProgrammatically check for when PTRSearchQueryFastResultsWithDelay = false

* Resoved some comments.

* Added partial delay for fast plugins

* Updates settings UI for second throttle value. Changed text.

* 'Verbiage' update
This commit is contained in:
Jeff Lord
2022-08-10 06:07:53 -04:00
committed by GitHub
parent 5d6160cf7a
commit 7f4a2ca6db
8 changed files with 285 additions and 61 deletions

View File

@@ -455,10 +455,15 @@ namespace PowerLauncher.ViewModel
}
public void Query()
{
Query(null);
}
public void Query(bool? delayedExecution)
{
if (SelectedIsFromQueryResults())
{
QueryResults();
QueryResults(delayedExecution);
}
else if (HistorySelected())
{
@@ -510,6 +515,11 @@ namespace PowerLauncher.ViewModel
}
private void QueryResults()
{
QueryResults(null);
}
private void QueryResults(bool? delayedExecution)
{
var queryTuning = GetQueryTuningOptions();
var doFinalSort = queryTuning.SearchQueryTuningEnabled && queryTuning.SearchWaitForSlowResults;
@@ -542,20 +552,44 @@ namespace PowerLauncher.ViewModel
// Contains all the plugins for which this raw query is valid
var plugins = pluginQueryPairs.Keys.ToList();
var sw = System.Diagnostics.Stopwatch.StartNew();
try
{
currentCancellationToken.ThrowIfCancellationRequested();
var resultPluginPair = new System.Collections.Concurrent.ConcurrentDictionary<PluginMetadata, List<Result>>();
var resultPluginPair = new List<(List<Result>, PluginMetadata)>();
// To execute a query corresponding to each plugin
foreach (KeyValuePair<PluginPair, Query> pluginQueryItem in pluginQueryPairs)
if (_settings.PTRunNonDelayedSearchInParallel)
{
Parallel.ForEach(pluginQueryPairs, (pluginQueryItem) =>
{
try
{
var plugin = pluginQueryItem.Key;
var query = pluginQueryItem.Value;
var results = PluginManager.QueryForPlugin(plugin, query);
resultPluginPair[plugin.Metadata] = results;
currentCancellationToken.ThrowIfCancellationRequested();
}
catch (OperationCanceledException)
{
// nothing to do here
}
});
sw.Stop();
}
else
{
var plugin = pluginQueryItem.Key;
var query = pluginQueryItem.Value;
var results = PluginManager.QueryForPlugin(plugin, query);
resultPluginPair.Add((results, plugin.Metadata));
currentCancellationToken.ThrowIfCancellationRequested();
// To execute a query corresponding to each plugin
foreach (KeyValuePair<PluginPair, Query> pluginQueryItem in pluginQueryPairs)
{
var plugin = pluginQueryItem.Key;
var query = pluginQueryItem.Value;
var results = PluginManager.QueryForPlugin(plugin, query);
resultPluginPair[plugin.Metadata] = results;
currentCancellationToken.ThrowIfCancellationRequested();
}
}
lock (_addResultsLock)
@@ -566,7 +600,7 @@ namespace PowerLauncher.ViewModel
Results.Clear();
foreach (var p in resultPluginPair)
{
UpdateResultView(p.Item1, queryText, currentCancellationToken);
UpdateResultView(p.Value, queryText, currentCancellationToken);
currentCancellationToken.ThrowIfCancellationRequested();
}
@@ -588,54 +622,56 @@ namespace PowerLauncher.ViewModel
bool noInitialResults = numResults == 0;
// Run the slower query of the DelayedExecution plugins
currentCancellationToken.ThrowIfCancellationRequested();
Parallel.ForEach(plugins, (plugin) =>
{
try
if (!delayedExecution.HasValue || delayedExecution.Value)
{
// Run the slower query of the DelayedExecution plugins
currentCancellationToken.ThrowIfCancellationRequested();
Parallel.ForEach(plugins, (plugin) =>
{
Query query;
pluginQueryPairs.TryGetValue(plugin, out query);
var results = PluginManager.QueryForPlugin(plugin, query, true);
currentCancellationToken.ThrowIfCancellationRequested();
if ((results?.Count ?? 0) != 0)
try
{
lock (_addResultsLock)
Query query;
pluginQueryPairs.TryGetValue(plugin, out query);
var results = PluginManager.QueryForPlugin(plugin, query, true);
currentCancellationToken.ThrowIfCancellationRequested();
if ((results?.Count ?? 0) != 0)
{
// Using CurrentCultureIgnoreCase since this is user facing
if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase))
lock (_addResultsLock)
{
currentCancellationToken.ThrowIfCancellationRequested();
// Using CurrentCultureIgnoreCase since this is user facing
if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase))
{
currentCancellationToken.ThrowIfCancellationRequested();
// Remove the original results from the plugin
Results.Results.RemoveAll(r => r.Result.PluginID == plugin.Metadata.ID);
currentCancellationToken.ThrowIfCancellationRequested();
// Remove the original results from the plugin
Results.Results.RemoveAll(r => r.Result.PluginID == plugin.Metadata.ID);
currentCancellationToken.ThrowIfCancellationRequested();
// Add the new results from the plugin
UpdateResultView(results, queryText, currentCancellationToken);
// Add the new results from the plugin
UpdateResultView(results, queryText, currentCancellationToken);
currentCancellationToken.ThrowIfCancellationRequested();
numResults = Results.Results.Count;
if (!doFinalSort)
{
Results.Sort(queryTuning);
}
}
currentCancellationToken.ThrowIfCancellationRequested();
numResults = Results.Results.Count;
if (!doFinalSort)
{
Results.Sort(queryTuning);
UpdateResultsListViewAfterQuery(queryText, noInitialResults, true);
}
}
currentCancellationToken.ThrowIfCancellationRequested();
if (!doFinalSort)
{
UpdateResultsListViewAfterQuery(queryText, noInitialResults, true);
}
}
}
}
catch (OperationCanceledException)
{
// nothing to do here
}
});
catch (OperationCanceledException)
{
// nothing to do here
}
});
}
}
catch (OperationCanceledException)
{
@@ -1135,6 +1171,11 @@ namespace PowerLauncher.ViewModel
return _settings.SearchQueryResultsWithDelay;
}
public int GetSearchInputDelayFastSetting()
{
return _settings.SearchInputDelayFast;
}
public int GetSearchInputDelaySetting()
{
return _settings.SearchInputDelay;