mirror of
https://github.com/unraid/api.git
synced 2025-12-31 21:49:57 -06:00
fix: debounce is too long (#1426)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Reduced the delay before configuration changes are processed, resulting in faster response times to configuration updates throughout the application. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -85,7 +85,7 @@ class ApiConfigPersistence {
|
|||||||
this.migrateFromMyServersConfig();
|
this.migrateFromMyServersConfig();
|
||||||
}
|
}
|
||||||
await this.persistenceHelper.persistIfChanged(this.filePath, this.config);
|
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 }) => {
|
next: async ({ newValue, oldValue, path }) => {
|
||||||
if (path.startsWith('api')) {
|
if (path.startsWith('api')) {
|
||||||
this.logger.verbose(`Config changed: ${path} from ${oldValue} to ${newValue}`);
|
this.logger.verbose(`Config changed: ${path} from ${oldValue} to ${newValue}`);
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ export class ConnectConfigPersister implements OnModuleInit, OnModuleDestroy {
|
|||||||
this.logger.verbose(`Config path: ${this.configPath}`);
|
this.logger.verbose(`Config path: ${this.configPath}`);
|
||||||
await this.loadOrMigrateConfig();
|
await this.loadOrMigrateConfig();
|
||||||
// Persist changes to the config.
|
// Persist changes to the config.
|
||||||
const HALF_SECOND = 500;
|
this.configService.changes$.pipe(debounceTime(25)).subscribe({
|
||||||
this.configService.changes$.pipe(debounceTime(HALF_SECOND)).subscribe({
|
|
||||||
next: async ({ newValue, oldValue, path }) => {
|
next: async ({ newValue, oldValue, path }) => {
|
||||||
if (path.startsWith('connect.config')) {
|
if (path.startsWith('connect.config')) {
|
||||||
this.logger.verbose(`Config changed: ${path} from ${oldValue} to ${newValue}`);
|
this.logger.verbose(`Config changed: ${path} from ${oldValue} to ${newValue}`);
|
||||||
|
|||||||
@@ -80,11 +80,10 @@ export class MothershipConnectionService implements OnModuleInit, OnModuleDestro
|
|||||||
if (this.identitySubscription) {
|
if (this.identitySubscription) {
|
||||||
this.identitySubscription.unsubscribe();
|
this.identitySubscription.unsubscribe();
|
||||||
}
|
}
|
||||||
const debounceTimeMs = 100;
|
|
||||||
this.identitySubscription = this.configService.changes$
|
this.identitySubscription = this.configService.changes$
|
||||||
.pipe(
|
.pipe(
|
||||||
filter((change) => Object.values(this.configKeys).includes(change.path)),
|
filter((change) => Object.values(this.configKeys).includes(change.path)),
|
||||||
debounceTime(debounceTimeMs)
|
debounceTime(25)
|
||||||
)
|
)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ export class PluginNameConfigPersister implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Automatically persist changes to the config file after a short delay.
|
// Automatically persist changes to the config file after a short delay.
|
||||||
const HALF_SECOND = 500;
|
this.configService.changes$.pipe(debounceTime(25)).subscribe({
|
||||||
this.configService.changes$.pipe(debounceTime(HALF_SECOND)).subscribe({
|
|
||||||
next: ({ newValue, oldValue, path: changedPath }) => {
|
next: ({ newValue, oldValue, path: changedPath }) => {
|
||||||
// Only persist if the change is within this plugin's config namespace
|
// Only persist if the change is within this plugin's config namespace
|
||||||
if (changedPath.startsWith("plugin-name.") && newValue !== oldValue) {
|
if (changedPath.startsWith("plugin-name.") && newValue !== oldValue) {
|
||||||
|
|||||||
Reference in New Issue
Block a user