mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-04-14 15:47:14 +03:00
Avoid redundant database queries when the Viewer tab is not visible
This commit is contained in:
parent
9341988017
commit
3e891e19c3
@ -5,7 +5,9 @@
|
||||
xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
|
||||
xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="DHT.Desktop.Main.Pages.ViewerPage">
|
||||
x:Class="DHT.Desktop.Main.Pages.ViewerPage"
|
||||
AttachedToVisualTree="OnAttachedToVisualTree"
|
||||
DetachedFromVisualTree="OnDetachedFromVisualTree">
|
||||
|
||||
<Design.DataContext>
|
||||
<pages:ViewerPageModel />
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
@ -12,5 +13,17 @@ namespace DHT.Desktop.Main.Pages {
|
||||
private void InitializeComponent() {
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e) {
|
||||
if (DataContext is ViewerPageModel model) {
|
||||
model.SetPageVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e) {
|
||||
if (DataContext is ViewerPageModel model) {
|
||||
model.SetPageVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ namespace DHT.Desktop.Main.Pages {
|
||||
private readonly Window window;
|
||||
private readonly IDatabaseFile db;
|
||||
|
||||
private bool isPageVisible = false;
|
||||
|
||||
[Obsolete("Designer")]
|
||||
public ViewerPageModel() : this(null!, DummyDatabaseFile.Instance) {}
|
||||
|
||||
@ -52,13 +54,20 @@ namespace DHT.Desktop.Main.Pages {
|
||||
FilterModel.Dispose();
|
||||
}
|
||||
|
||||
public void SetPageVisible(bool isPageVisible) {
|
||||
this.isPageVisible = isPageVisible;
|
||||
if (isPageVisible) {
|
||||
UpdateStatistics();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFilterPropertyChanged(object? sender, PropertyChangedEventArgs e) {
|
||||
UpdateStatistics();
|
||||
HasFilters = FilterModel.HasAnyFilters;
|
||||
}
|
||||
|
||||
private void OnDbStatisticsChanged(object? sender, PropertyChangedEventArgs e) {
|
||||
if (e.PropertyName == nameof(DatabaseStatistics.TotalMessages)) {
|
||||
if (isPageVisible && e.PropertyName == nameof(DatabaseStatistics.TotalMessages)) {
|
||||
UpdateStatistics();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user