@@ -244,7 +244,7 @@ private void InitializeKeyCommands()
244
244
245
245
public string QueryText
246
246
{
247
- get { return _queryText ; }
247
+ get => _queryText ;
248
248
set
249
249
{
250
250
_queryText = value ;
@@ -444,28 +444,26 @@ private void QueryResults()
444
444
var plugins = PluginManager . ValidPluginsForQuery ( query ) ;
445
445
446
446
Task . Run ( async ( ) =>
447
- {
448
- if ( query . ActionKeyword == Plugin . Query . GlobalPluginWildcardSign )
449
- {
450
- // Wait 45 millisecond for query change in global query
451
- // if query changes, return so that it won't be calculated
452
- await Task . Delay ( 45 , currentCancellationToken ) ;
453
- if ( currentCancellationToken . IsCancellationRequested )
454
- return ;
455
- }
456
-
457
- _ = Task . Delay ( 200 , currentCancellationToken ) . ContinueWith ( _ =>
458
447
{
459
- // start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
460
- if ( ! currentCancellationToken . IsCancellationRequested && _isQueryRunning )
448
+ if ( query . ActionKeyword == Plugin . Query . GlobalPluginWildcardSign )
461
449
{
462
- ProgressBarVisibility = Visibility . Visible ;
450
+ // Wait 45 millisecond for query change in global query
451
+ // if query changes, return so that it won't be calculated
452
+ await Task . Delay ( 45 , currentCancellationToken ) ;
453
+ if ( currentCancellationToken . IsCancellationRequested )
454
+ return ;
463
455
}
464
- } , currentCancellationToken ) ;
465
456
466
- var plugins = PluginManager . ValidPluginsForQuery ( query ) ;
467
- Task . Run ( async ( ) =>
468
- {
457
+ _ = Task . Delay ( 200 , currentCancellationToken ) . ContinueWith ( _ =>
458
+ {
459
+ // start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
460
+ if ( ! currentCancellationToken . IsCancellationRequested && _isQueryRunning )
461
+ {
462
+ ProgressBarVisibility = Visibility . Visible ;
463
+ }
464
+ } , currentCancellationToken ) ;
465
+
466
+ var plugins = PluginManager . ValidPluginsForQuery ( query ) ;
469
467
// so looping will stop once it was cancelled
470
468
471
469
Task [ ] tasks = new Task [ plugins . Count ] ;
@@ -475,7 +473,7 @@ private void QueryResults()
475
473
{
476
474
if ( ! plugins [ i ] . Metadata . Disabled )
477
475
{
478
- tasks [ i ] = QueryTask ( plugins [ i ] , query , currentCancellationToken ) ;
476
+ tasks [ i ] = QueryTask ( plugins [ i ] ) ;
479
477
}
480
478
else
481
479
{
@@ -491,6 +489,9 @@ private void QueryResults()
491
489
// nothing to do here
492
490
}
493
491
492
+ if ( currentCancellationToken . IsCancellationRequested )
493
+ return ;
494
+
494
495
// this should happen once after all queries are done so progress bar should continue
495
496
// until the end of all querying
496
497
_isQueryRunning = false ;
@@ -501,28 +502,20 @@ private void QueryResults()
501
502
}
502
503
503
504
// Local function
504
- async Task QueryTask ( PluginPair plugin , Query query , CancellationToken token )
505
+ async Task QueryTask ( PluginPair plugin )
505
506
{
506
507
// Since it is wrapped within a Task.Run, the synchronous context is null
507
508
// Task.Yield will force it to run in ThreadPool
508
509
await Task . Yield ( ) ;
509
510
510
- var results = await PluginManager . QueryForPlugin ( plugin , query , token ) ;
511
+ var results = await PluginManager . QueryForPlugin ( plugin , query , currentCancellationToken ) ;
511
512
if ( ! currentCancellationToken . IsCancellationRequested )
512
- UpdateResultView ( results , plugin . Metadata , query ) ;
513
+ _resultsUpdateQueue . Post ( new ResultsForUpdate ( results , plugin . Metadata , query ,
514
+ currentCancellationToken ) ) ;
513
515
}
514
- } , currentCancellationToken ) . ContinueWith (
515
- t => Log . Exception ( "|MainViewModel|Plugins Query Exceptions" , t . Exception ) ,
516
+ } , currentCancellationToken )
517
+ . ContinueWith ( t => Log . Exception ( "|MainViewModel|Plugins Query Exceptions" , t . Exception ) ,
516
518
TaskContinuationOptions . OnlyOnFaulted ) ;
517
-
518
-
519
- else
520
-
521
- {
522
- Results . Clear ( ) ;
523
- Results . Visbility = Visibility . Collapsed ;
524
- }
525
- }
526
519
}
527
520
528
521
@@ -786,7 +779,7 @@ public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
786
779
}
787
780
else
788
781
{
789
- var priorityScore = metaResults . Metadata . Priority * 50 ;
782
+ var priorityScore = metaResults . Metadata . Priority * 150 ;
790
783
result . Score += _userSelectedRecord . GetSelectedCount ( result ) * 5 + priorityScore ;
791
784
}
792
785
}
@@ -795,30 +788,6 @@ public void UpdateResultView(IEnumerable<ResultsForUpdate> resultsForUpdates)
795
788
Results . AddResults ( resultsForUpdates , token ) ;
796
789
}
797
790
798
- /// <summary>U
799
- /// To avoid deadlock, this method should not called from main thread
800
- /// </summary>
801
- public void UpdateResultView ( List < Result > list , PluginMetadata metadata , Query originQuery )
802
- {
803
- foreach ( var result in list )
804
- {
805
- if ( _topMostRecord . IsTopMost ( result ) )
806
- {
807
- result . Score = int . MaxValue ;
808
- }
809
- else
810
- {
811
- var priorityScore = metadata . Priority * 150 ;
812
- result . Score += _userSelectedRecord . GetSelectedCount ( result ) * 5 + priorityScore ;
813
- }
814
- }
815
-
816
- if ( originQuery . RawQuery == _lastQuery . RawQuery )
817
- {
818
- Results . AddResults ( list , metadata . ID ) ;
819
- }
820
- }
821
-
822
791
#endregion
823
792
}
824
793
}
0 commit comments