From 7d10bb00f739f83fbefcedf89dd5efc6fca1fd20 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Fri, 15 Aug 2025 21:16:51 +0200 Subject: [PATCH] Applied several small fixes (#536) --- app/MindWork AI Studio.sln.DotSettings | 2 + .../Assistants/AssistantBase.razor.cs | 12 +++++- .../Components/ConfigurationText.razor.cs | 19 ++++++++++ .../Components/DebouncedTextField.razor.cs | 38 ++++++++++++++++--- app/MindWork AI Studio/Pages/Chat.razor.cs | 19 +++++++++- app/MindWork AI Studio/Pages/Writer.razor.cs | 19 ++++++++++ .../wwwroot/changelog/v0.9.51.md | 3 +- 7 files changed, 103 insertions(+), 9 deletions(-) diff --git a/app/MindWork AI Studio.sln.DotSettings b/app/MindWork AI Studio.sln.DotSettings index d85707aa..faaedb6b 100644 --- a/app/MindWork AI Studio.sln.DotSettings +++ b/app/MindWork AI Studio.sln.DotSettings @@ -5,6 +5,7 @@ FNV GWDG HF + IERI LLM LM MSG @@ -20,6 +21,7 @@ True True True + True True True True \ No newline at end of file diff --git a/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs b/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs index c355fba1..39bf2659 100644 --- a/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs +++ b/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs @@ -384,7 +384,17 @@ public abstract partial class AssistantBase : AssistantLowerBase wher protected override void DisposeResources() { - this.formChangeTimer.Dispose(); + try + { + this.formChangeTimer.Stop(); + this.formChangeTimer.Dispose(); + } + catch + { + // ignore + } + + base.DisposeResources(); } #endregion diff --git a/app/MindWork AI Studio/Components/ConfigurationText.razor.cs b/app/MindWork AI Studio/Components/ConfigurationText.razor.cs index 7bcce41e..5074fa73 100644 --- a/app/MindWork AI Studio/Components/ConfigurationText.razor.cs +++ b/app/MindWork AI Studio/Components/ConfigurationText.razor.cs @@ -92,4 +92,23 @@ public partial class ConfigurationText : ConfigurationBaseCore await this.SettingsManager.StoreSettings(); await this.InformAboutChange(); } + + #region Overrides of MSGComponentBase + + protected override void DisposeResources() + { + try + { + this.timer.Stop(); + this.timer.Dispose(); + } + catch + { + // ignore + } + + base.DisposeResources(); + } + + #endregion } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/DebouncedTextField.razor.cs b/app/MindWork AI Studio/Components/DebouncedTextField.razor.cs index a1fd256b..3ad55c6a 100644 --- a/app/MindWork AI Studio/Components/DebouncedTextField.razor.cs +++ b/app/MindWork AI Studio/Components/DebouncedTextField.razor.cs @@ -4,7 +4,7 @@ using Timer = System.Timers.Timer; namespace AIStudio.Components; -public partial class DebouncedTextField : MudComponentBase +public partial class DebouncedTextField : MudComponentBase, IDisposable { [Parameter] public string Label { get; set; } = string.Empty; @@ -51,6 +51,7 @@ public partial class DebouncedTextField : MudComponentBase private readonly Timer debounceTimer = new(); private string text = string.Empty; private string lastParameterText = string.Empty; + private bool isInitialized; #region Overrides of ComponentBase @@ -68,20 +69,30 @@ public partial class DebouncedTextField : MudComponentBase this.InvokeAsync(() => this.WhenTextCanged(this.text)); }; + this.isInitialized = true; await base.OnInitializedAsync(); } - protected override void OnParametersSet() + protected override async Task OnParametersSetAsync() { + // Ensure the timer uses the latest debouncing interval: + if (!this.isInitialized) + return; + + if(Math.Abs(this.debounceTimer.Interval - this.DebounceTime.TotalMilliseconds) > 1) + this.debounceTimer.Interval = this.DebounceTime.TotalMilliseconds; + // Only sync when the parent's parameter actually changed since the last change: if (this.Text != this.lastParameterText) { this.text = this.Text; this.lastParameterText = this.Text; - - this.debounceTimer.Stop(); - this.debounceTimer.Start(); } + + this.debounceTimer.Stop(); + this.debounceTimer.Start(); + + await base.OnParametersSetAsync(); } #endregion @@ -92,4 +103,21 @@ public partial class DebouncedTextField : MudComponentBase this.debounceTimer.Stop(); this.debounceTimer.Start(); } + + #region IDisposable + + public void Dispose() + { + try + { + this.debounceTimer.Stop(); + this.debounceTimer.Dispose(); + } + catch + { + // ignore + } + } + + #endregion } \ No newline at end of file diff --git a/app/MindWork AI Studio/Pages/Chat.razor.cs b/app/MindWork AI Studio/Pages/Chat.razor.cs index e411a9fa..deeda47f 100644 --- a/app/MindWork AI Studio/Pages/Chat.razor.cs +++ b/app/MindWork AI Studio/Pages/Chat.razor.cs @@ -100,6 +100,23 @@ public partial class Chat : MSGComponentBase #region Overrides of MSGComponentBase + protected override void DisposeResources() + { + try + { + this.splitterSaveTimer.Stop(); + this.splitterSaveTimer.Dispose(); + } + catch + { + // ignore + } + + base.DisposeResources(); + } + + #endregion + protected override Task ProcessIncomingMessage(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default { switch (triggeredEvent) @@ -111,6 +128,4 @@ public partial class Chat : MSGComponentBase return Task.CompletedTask; } - - #endregion } \ No newline at end of file diff --git a/app/MindWork AI Studio/Pages/Writer.razor.cs b/app/MindWork AI Studio/Pages/Writer.razor.cs index 6c137108..56fd0c5d 100644 --- a/app/MindWork AI Studio/Pages/Writer.razor.cs +++ b/app/MindWork AI Studio/Pages/Writer.razor.cs @@ -152,4 +152,23 @@ public partial class Writer : MSGComponentBase this.suggestion = string.Join(' ', words.Skip(1)); this.StateHasChanged(); } + + #region Overrides of MSGComponentBase + + protected override void DisposeResources() + { + try + { + this.typeTimer.Stop(); + this.typeTimer.Dispose(); + } + catch + { + // ignore + } + + base.DisposeResources(); + } + + #endregion } \ No newline at end of file diff --git a/app/MindWork AI Studio/wwwroot/changelog/v0.9.51.md b/app/MindWork AI Studio/wwwroot/changelog/v0.9.51.md index ef784978..8e3eaf85 100644 --- a/app/MindWork AI Studio/wwwroot/changelog/v0.9.51.md +++ b/app/MindWork AI Studio/wwwroot/changelog/v0.9.51.md @@ -1,2 +1,3 @@ # v0.9.51, build 226 (2025-08-xx xx:xx UTC) -- Fixed a bug in various assistants where some text fields were not reset when resetting. \ No newline at end of file +- Improved memory usage in several areas of the app. +- Fixed a bug in various assistants where some text fields were not reset when resetting.