Skip to content

Commit 5dd19bf

Browse files
committed
add warmup for bulkupdate
1 parent 5c225cc commit 5dd19bf

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Flow.Launcher/ViewModel/ResultsViewModel.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Windows.Controls;
99
using System.Windows.Data;
1010
using System.Windows.Documents;
11+
using ABI.Windows.Services.Maps;
1112

1213
namespace Flow.Launcher.ViewModel
1314
{
@@ -26,6 +27,7 @@ public ResultsViewModel()
2627
Results = new ResultCollection();
2728
BindingOperations.EnableCollectionSynchronization(Results, _collectionLock);
2829
}
30+
2931
public ResultsViewModel(Settings settings) : this()
3032
{
3133
_settings = settings;
@@ -65,6 +67,7 @@ private int InsertIndexOf(int newScore, IList<ResultViewModel> list)
6567
break;
6668
}
6769
}
70+
6871
return index;
6972
}
7073

@@ -83,7 +86,6 @@ private int NewIndex(int i)
8386
}
8487
}
8588

86-
8789
#endregion
8890

8991
#region Public Methods
@@ -140,6 +142,7 @@ public void AddResults(List<Result> newRawResults, string resultId)
140142

141143
UpdateResults(newResults);
142144
}
145+
143146
/// <summary>
144147
/// To avoid deadlock, this method should not called from main thread
145148
/// </summary>
@@ -166,12 +169,12 @@ private void UpdateResults(List<ResultViewModel> newResults, CancellationToken t
166169
switch (Visbility)
167170
{
168171
case Visibility.Collapsed when Results.Count > 0:
169-
Margin = new Thickness { Top = 8 };
172+
Margin = new Thickness {Top = 8};
170173
SelectedIndex = 0;
171174
Visbility = Visibility.Visible;
172175
break;
173176
case Visibility.Visible when Results.Count == 0:
174-
Margin = new Thickness { Top = 0 };
177+
Margin = new Thickness {Top = 0};
175178
Visbility = Visibility.Collapsed;
176179
break;
177180
}
@@ -197,13 +200,15 @@ private List<ResultViewModel> NewResults(IEnumerable<ResultsForUpdate> resultsFo
197200
return Results;
198201

199202
return Results.Where(r => r != null && !resultsForUpdates.Any(u => u.ID == r.Result.PluginID))
200-
.Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
201-
.OrderByDescending(rv => rv.Result.Score)
202-
.ToList();
203+
.Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
204+
.OrderByDescending(rv => rv.Result.Score)
205+
.ToList();
203206
}
207+
204208
#endregion
205209

206210
#region FormattedText Dependency Property
211+
207212
public static readonly DependencyProperty FormattedTextProperty = DependencyProperty.RegisterAttached(
208213
"FormattedText",
209214
typeof(Inline),
@@ -217,21 +222,22 @@ public static void SetFormattedText(DependencyObject textBlock, IList<int> value
217222

218223
public static Inline GetFormattedText(DependencyObject textBlock)
219224
{
220-
return (Inline)textBlock.GetValue(FormattedTextProperty);
225+
return (Inline) textBlock.GetValue(FormattedTextProperty);
221226
}
222227

223228
private static void FormattedTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
224229
{
225230
var textBlock = d as TextBlock;
226231
if (textBlock == null) return;
227232

228-
var inline = (Inline)e.NewValue;
233+
var inline = (Inline) e.NewValue;
229234

230235
textBlock.Inlines.Clear();
231236
if (inline == null) return;
232237

233238
textBlock.Inlines.Add(inline);
234239
}
240+
235241
#endregion
236242

237243
public class ResultCollection : List<ResultViewModel>, INotifyCollectionChanged
@@ -260,6 +266,7 @@ public void BulkAddAll(List<ResultViewModel> resultViews)
260266
// wpf use directx / double buffered already, so just reset all won't cause ui flickering
261267
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
262268
}
269+
263270
private void AddAll(List<ResultViewModel> Items)
264271
{
265272
for (int i = 0; i < Items.Count; i++)
@@ -268,9 +275,11 @@ private void AddAll(List<ResultViewModel> Items)
268275
if (_token.IsCancellationRequested)
269276
return;
270277
Add(item);
271-
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, i));
278+
OnCollectionChanged(
279+
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, i));
272280
}
273281
}
282+
274283
public void RemoveAll(int Capacity = 512)
275284
{
276285
Clear();
@@ -299,12 +308,16 @@ public void Update(List<ResultViewModel> newItems, CancellationToken token = def
299308
}
300309
else
301310
{
311+
if (editTime < 5)
312+
AddAll(newItems.GetRange(0, 100));
302313
Clear();
314+
303315
BulkAddAll(newItems);
304316
if (Capacity > 8000 && newItems.Count < 3000)
305317
{
306318
Capacity = newItems.Count;
307319
}
320+
308321
editTime++;
309322
}
310323
}

0 commit comments

Comments
 (0)