Skip to content

Commit

Permalink
Manager: Use DebounceThrottle library for debouncing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejsel committed Oct 8, 2023
1 parent ff405e1 commit d0358a9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 90 deletions.
1 change: 1 addition & 0 deletions ArcdpsLogManager/ArcdpsLogManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<Version>1.10.0.5</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DebounceThrottle" Version="2.0.0" />
<PackageReference Include="Eto.Forms" Version="2.6.1" />
<PackageReference Include="Gw2Sharp" Version="0.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
Expand Down
1 change: 1 addition & 0 deletions ArcdpsLogManager/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This is the full changelog of the arcdps Log Manager.
- Improved log processing performance ~1.25x for 10man logs, even more in WvW logs.
- Also improved log processing performance by further ~2.60x for all logs (~35% of original time).
- Yes, that is about 3.25x speedup overall.
- Also made character and guild search more responsive (thank you, @Denrage!).

#### Fixes
- Fixed Harvest Temple success detection.
Expand Down
53 changes: 8 additions & 45 deletions ArcdpsLogManager/Sections/GuildList.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DebounceThrottle;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -26,8 +27,8 @@ public class GuildList : DynamicLayout

private ObservableCollection<GuildData> guildData;
private SelectableFilterCollection<GuildData> filtered;
private Task debounceFilterTask;
private CancellationTokenSource debounceFilterCancellationTokenSource;

private readonly DebounceDispatcher debounceDispatcher = new DebounceDispatcher(200);

private readonly GridViewSorter<GuildData> sorter;
private readonly GridView<GuildData> guildGridView;
Expand Down Expand Up @@ -77,53 +78,15 @@ public GuildList(LogCache logCache, ApiData apiData, LogDataProcessor logProcess

var playerFilterBox = new TextBox();
playerFilterBox.TextBinding.Bind(this, x => x.GuildFilter);
playerFilterBox.TextChanged += (sender, args) =>
playerFilterBox.TextChanged += (_, _) =>
{
if (this.debounceFilterCancellationTokenSource != null)
{
this.debounceFilterCancellationTokenSource.Cancel();
try
{
this.debounceFilterTask.Wait();
}
catch (AggregateException ex)
{
if (ex.InnerException is TaskCanceledException)
{
// NOP
}
else
{
throw;
}
}
this.debounceFilterTask.Dispose();
this.debounceFilterCancellationTokenSource.Dispose();
this.debounceFilterTask = null;
this.debounceFilterCancellationTokenSource = null;
}
this.debounceFilterCancellationTokenSource = new CancellationTokenSource();
this.debounceFilterTask = Task.Run(async () =>
{
await Task.Delay(200, this.debounceFilterCancellationTokenSource.Token);
this.debounceFilterCancellationTokenSource.Token.ThrowIfCancellationRequested();
await Application.Instance.InvokeAsync(() =>
debounceDispatcher.Debounce(() =>
Application.Instance.InvokeAsync(() =>
{
guildGridView.UnselectAll();
Refresh();
});
_ = Task.Run(() =>
{
this.debounceFilterCancellationTokenSource.Cancel();
this.debounceFilterTask.Wait();
this.debounceFilterTask.Dispose();
this.debounceFilterCancellationTokenSource.Dispose();
this.debounceFilterTask = null;
this.debounceFilterCancellationTokenSource = null;
});
});
})
);
};

BeginVertical(spacing: new Size(5, 5), padding: new Padding(5));
Expand Down
51 changes: 6 additions & 45 deletions ArcdpsLogManager/Sections/PlayerList.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DebounceThrottle;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -26,8 +27,7 @@ public class PlayerList : DynamicLayout

private ObservableCollection<PlayerData> playerData;
private SelectableFilterCollection<PlayerData> filtered;
private Task debounceFilterTask;
private CancellationTokenSource debounceFilterCancellationTokenSource;
private readonly DebounceDispatcher debounceDispatcher = new DebounceDispatcher(200);

private readonly GridView<PlayerData> playerGridView;
private readonly GridViewSorter<PlayerData> sorter;
Expand Down Expand Up @@ -85,52 +85,13 @@ public PlayerList(LogCache logCache, ApiData apiData, LogDataProcessor logProces
var playerFilterBox = new TextBox();
playerFilterBox.TextBinding.Bind(this, x => x.PlayerFilter);
playerFilterBox.TextChanged += (sender, args) => {
if (this.debounceFilterCancellationTokenSource != null)
{
this.debounceFilterCancellationTokenSource.Cancel();
try
{
this.debounceFilterTask.Wait();
}
catch (AggregateException ex)
{
if (ex.InnerException is TaskCanceledException)
{
// NOP
}
else
{
throw;
}
}
this.debounceFilterTask.Dispose();
this.debounceFilterCancellationTokenSource.Dispose();
this.debounceFilterTask = null;
this.debounceFilterCancellationTokenSource = null;
}
this.debounceFilterCancellationTokenSource = new CancellationTokenSource();
this.debounceFilterTask = Task.Run(async () =>
{
await Task.Delay(200, this.debounceFilterCancellationTokenSource.Token);
this.debounceFilterCancellationTokenSource.Token.ThrowIfCancellationRequested();
await Application.Instance.InvokeAsync(() =>
debounceDispatcher.Debounce(() =>
Application.Instance.InvokeAsync(() =>
{
playerGridView.UnselectAll();
Refresh();
});
_ = Task.Run(() =>
{
this.debounceFilterCancellationTokenSource.Cancel();
this.debounceFilterTask.Wait();
this.debounceFilterTask.Dispose();
this.debounceFilterCancellationTokenSource.Dispose();
this.debounceFilterTask = null;
this.debounceFilterCancellationTokenSource = null;
});
});
})
);
};

BeginVertical(spacing: new Size(5, 5), padding: new Padding(5));
Expand Down

0 comments on commit d0358a9

Please sign in to comment.