From f12d231e6376d0f253cee67b7ed690c432c63ec5 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Fri, 20 Jun 2025 11:07:53 -0400 Subject: [PATCH] fix: debounce is too long (#1426) ## Summary by CodeRabbit - **Refactor** - Reduced the delay before configuration changes are processed, resulting in faster response times to configuration updates throughout the application. --- api/src/unraid-api/config/api-config.module.ts | 2 +- .../src/service/config.persistence.ts | 3 +-- .../src/service/connection.service.ts | 3 +-- .../src/templates/config.persistence.ts | 3 +-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/api/src/unraid-api/config/api-config.module.ts b/api/src/unraid-api/config/api-config.module.ts index 39dc547f7..8c167a14b 100644 --- a/api/src/unraid-api/config/api-config.module.ts +++ b/api/src/unraid-api/config/api-config.module.ts @@ -85,7 +85,7 @@ class ApiConfigPersistence { this.migrateFromMyServersConfig(); } await this.persistenceHelper.persistIfChanged(this.filePath, this.config); - this.configService.changes$.pipe(debounceTime(500)).subscribe({ + this.configService.changes$.pipe(debounceTime(25)).subscribe({ next: async ({ newValue, oldValue, path }) => { if (path.startsWith('api')) { this.logger.verbose(`Config changed: ${path} from ${oldValue} to ${newValue}`); diff --git a/packages/unraid-api-plugin-connect/src/service/config.persistence.ts b/packages/unraid-api-plugin-connect/src/service/config.persistence.ts index 4a7a0a619..d7c272433 100644 --- a/packages/unraid-api-plugin-connect/src/service/config.persistence.ts +++ b/packages/unraid-api-plugin-connect/src/service/config.persistence.ts @@ -33,8 +33,7 @@ export class ConnectConfigPersister implements OnModuleInit, OnModuleDestroy { this.logger.verbose(`Config path: ${this.configPath}`); await this.loadOrMigrateConfig(); // Persist changes to the config. - const HALF_SECOND = 500; - this.configService.changes$.pipe(debounceTime(HALF_SECOND)).subscribe({ + this.configService.changes$.pipe(debounceTime(25)).subscribe({ next: async ({ newValue, oldValue, path }) => { if (path.startsWith('connect.config')) { this.logger.verbose(`Config changed: ${path} from ${oldValue} to ${newValue}`); diff --git a/packages/unraid-api-plugin-connect/src/service/connection.service.ts b/packages/unraid-api-plugin-connect/src/service/connection.service.ts index 1cdc4ab36..e1099724a 100644 --- a/packages/unraid-api-plugin-connect/src/service/connection.service.ts +++ b/packages/unraid-api-plugin-connect/src/service/connection.service.ts @@ -80,11 +80,10 @@ export class MothershipConnectionService implements OnModuleInit, OnModuleDestro if (this.identitySubscription) { this.identitySubscription.unsubscribe(); } - const debounceTimeMs = 100; this.identitySubscription = this.configService.changes$ .pipe( filter((change) => Object.values(this.configKeys).includes(change.path)), - debounceTime(debounceTimeMs) + debounceTime(25) ) .subscribe({ next: () => { diff --git a/packages/unraid-api-plugin-generator/src/templates/config.persistence.ts b/packages/unraid-api-plugin-generator/src/templates/config.persistence.ts index 6d57d1360..cd8b574c8 100644 --- a/packages/unraid-api-plugin-generator/src/templates/config.persistence.ts +++ b/packages/unraid-api-plugin-generator/src/templates/config.persistence.ts @@ -42,8 +42,7 @@ export class PluginNameConfigPersister implements OnModuleInit { } // Automatically persist changes to the config file after a short delay. - const HALF_SECOND = 500; - this.configService.changes$.pipe(debounceTime(HALF_SECOND)).subscribe({ + this.configService.changes$.pipe(debounceTime(25)).subscribe({ next: ({ newValue, oldValue, path: changedPath }) => { // Only persist if the change is within this plugin's config namespace if (changedPath.startsWith("plugin-name.") && newValue !== oldValue) {