Compare commits

..

No commits in common. "277e241183480d4784aa4ea9008c2c85117cfc07" and "6ce0ef7d55d73b632bfef379e0969cd483cc58b0" have entirely different histories.

6 changed files with 15 additions and 28 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 value == null ? "-" : string.Format(Program.Culture, "{0:n0}", value); return 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,8 +92,6 @@ 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;
@ -134,7 +132,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 = target.CountMessages() - oldMessageCount; long newMessages = newStatistics.TotalMessages - oldStatistics.TotalMessages;
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
message.Append("Processed "); message.Append("Processed ");

View File

@ -35,7 +35,7 @@ namespace DHT.Desktop.Main.Pages {
private readonly IDatabaseFile db; private readonly IDatabaseFile db;
private bool isPageVisible = false; private bool isPageVisible = false;
[Obsolete("Designer")] [Obsolete("Designer")]
public ViewerPageModel() : this(null!, DummyDatabaseFile.Instance) {} public ViewerPageModel() : this(null!, DummyDatabaseFile.Instance) {}
@ -46,6 +46,7 @@ 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() {
@ -72,17 +73,13 @@ namespace DHT.Desktop.Main.Pages {
} }
private void UpdateStatistics() { private void UpdateStatistics() {
var filter = FilterModel.CreateFilter(); ExportedMessageText = "Will export " + db.CountMessages(FilterModel.CreateFilter()).Format() + " out of " + db.Statistics.TotalMessages.Format() + " message(s).";
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));
} }
private async Task<string> GenerateViewerContents() { private async Task<string> GenerateViewerContents() {
string json = ViewerJsonExport.Generate(db, FilterModel.CreateFilter()); string json = ViewerJsonExport.Generate(db, FilterModel.CreateFilter());
string index = await Resources.ReadTextAsync("Viewer/index.html"); string index = await Resources.ReadTextAsync("Viewer/index.html");
string viewer = index.Replace("/*[JS]*/", await Resources.ReadJoinedAsync("Viewer/scripts/", '\n')) string viewer = index.Replace("/*[JS]*/", await Resources.ReadJoinedAsync("Viewer/scripts/", '\n'))
.Replace("/*[CSS]*/", await Resources.ReadJoinedAsync("Viewer/styles/", '\n')) .Replace("/*[CSS]*/", await Resources.ReadJoinedAsync("Viewer/styles/", '\n'))

View File

@ -3,17 +3,11 @@ 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; } = null; public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; } = null; public DateTime? EndDate { get; set; }
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,13 +46,11 @@ 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() {