Compare commits

...

2 Commits

6 changed files with 28 additions and 15 deletions

View File

@ -5,7 +5,7 @@ using Avalonia.Data.Converters;
namespace DHT.Desktop.Common { namespace DHT.Desktop.Common {
sealed class NumberValueConverter : IValueConverter { sealed class NumberValueConverter : IValueConverter {
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
return string.Format(Program.Culture, "{0:n0}", value); return value == null ? "-" : string.Format(Program.Culture, "{0:n0}", value);
} }
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) {

View File

@ -92,6 +92,8 @@ namespace DHT.Desktop.Main.Pages {
} }
var oldStatistics = target.Statistics.Clone(); var oldStatistics = target.Statistics.Clone();
var oldMessageCount = target.CountMessages();
int successful = 0; int successful = 0;
int finished = 0; int finished = 0;
@ -132,7 +134,7 @@ namespace DHT.Desktop.Main.Pages {
var newStatistics = target.Statistics; var newStatistics = target.Statistics;
long newServers = newStatistics.TotalServers - oldStatistics.TotalServers; long newServers = newStatistics.TotalServers - oldStatistics.TotalServers;
long newChannels = newStatistics.TotalChannels - oldStatistics.TotalChannels; long newChannels = newStatistics.TotalChannels - oldStatistics.TotalChannels;
long newMessages = newStatistics.TotalMessages - oldStatistics.TotalMessages; long newMessages = target.CountMessages() - oldMessageCount;
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
message.Append("Processed "); message.Append("Processed ");

View File

@ -46,7 +46,6 @@ namespace DHT.Desktop.Main.Pages {
FilterModel = new FilterPanelModel(window, db); FilterModel = new FilterPanelModel(window, db);
FilterModel.FilterPropertyChanged += OnFilterPropertyChanged; FilterModel.FilterPropertyChanged += OnFilterPropertyChanged;
db.Statistics.PropertyChanged += OnDbStatisticsChanged; db.Statistics.PropertyChanged += OnDbStatisticsChanged;
UpdateStatistics();
} }
public void Dispose() { public void Dispose() {
@ -73,7 +72,11 @@ namespace DHT.Desktop.Main.Pages {
} }
private void UpdateStatistics() { private void UpdateStatistics() {
ExportedMessageText = "Will export " + db.CountMessages(FilterModel.CreateFilter()).Format() + " out of " + db.Statistics.TotalMessages.Format() + " message(s)."; var filter = FilterModel.CreateFilter();
var allMessagesCount = db.Statistics.TotalMessages?.Format() ?? "?";
var filteredMessagesCount = filter.IsEmpty ? allMessagesCount : db.CountMessages(filter).Format();
ExportedMessageText = "Will export " + filteredMessagesCount + " out of " + allMessagesCount + " message(s).";
OnPropertyChanged(nameof(ExportedMessageText)); OnPropertyChanged(nameof(ExportedMessageText));
} }

View File

@ -3,11 +3,17 @@ using System.Collections.Generic;
namespace DHT.Server.Data.Filters { namespace DHT.Server.Data.Filters {
public sealed class MessageFilter { public sealed class MessageFilter {
public DateTime? StartDate { get; set; } public DateTime? StartDate { get; set; } = null;
public DateTime? EndDate { get; set; } public DateTime? EndDate { get; set; } = null;
public HashSet<ulong>? ChannelIds { get; set; } = null; public HashSet<ulong>? ChannelIds { get; set; } = null;
public HashSet<ulong>? UserIds { get; set; } = null; public HashSet<ulong>? UserIds { get; set; } = null;
public HashSet<ulong>? MessageIds { get; set; } = null; public HashSet<ulong>? MessageIds { get; set; } = null;
public bool IsEmpty => StartDate == null &&
EndDate == null &&
ChannelIds == null &&
UserIds == null &&
MessageIds == null;
} }
} }

View File

@ -5,7 +5,7 @@ namespace DHT.Server.Database {
private long totalServers; private long totalServers;
private long totalChannels; private long totalChannels;
private long totalUsers; private long totalUsers;
private long totalMessages; private long? totalMessages;
public long TotalServers { public long TotalServers {
get => totalServers; get => totalServers;
@ -22,7 +22,7 @@ namespace DHT.Server.Database {
internal set => Change(ref totalUsers, value); internal set => Change(ref totalUsers, value);
} }
public long TotalMessages { public long? TotalMessages {
get => totalMessages; get => totalMessages;
internal set => Change(ref totalMessages, value); internal set => Change(ref totalMessages, value);
} }

View File

@ -46,11 +46,13 @@ namespace DHT.Server.Database.Sqlite {
this.Path = path; this.Path = path;
this.Statistics = new DatabaseStatistics(); this.Statistics = new DatabaseStatistics();
using var conn = pool.Take(); using (var conn = pool.Take()) {
UpdateServerStatistics(conn); UpdateServerStatistics(conn);
UpdateChannelStatistics(conn); UpdateChannelStatistics(conn);
UpdateUserStatistics(conn); UpdateUserStatistics(conn);
UpdateMessageStatistics(conn); }
messageStatisticsThread.RequestUpdate();
} }
public void Dispose() { public void Dispose() {