Skip to content

Commit b3e2a21

Browse files
committed
cleanup
1 parent 041b376 commit b3e2a21

File tree

3 files changed

+13
-34
lines changed

3 files changed

+13
-34
lines changed

api/src/unraid-api/config/store-sync.service.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@ import { Injectable, Logger, OnModuleDestroy } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
33

44
import type { Unsubscribe } from '@reduxjs/toolkit';
5-
import { isEqual } from 'lodash-es';
65

76
import { store } from '@app/store/index.js';
87

98
@Injectable()
109
export class StoreSyncService implements OnModuleDestroy {
1110
private unsubscribe: Unsubscribe;
1211
private logger = new Logger(StoreSyncService.name);
13-
private lastState: object | null = null;
1412

1513
constructor(private configService: ConfigService) {
1614
this.unsubscribe = store.subscribe(() => {
17-
const currentState = store.getState();
18-
if (isEqual(currentState, this.lastState)) {
19-
this.logger.debug('Store state unchanged; skipping sync');
20-
return;
21-
}
22-
this.lastState = structuredClone(currentState);
2315
this.configService.set('store', store.getState());
2416
this.logger.verbose('Synced store to NestJS Config');
2517
});

packages/unraid-api-plugin-connect/src/mothership-proxy/connection.service.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import type { OutgoingHttpHeaders } from 'node:http2';
55

66
import { isEqual } from 'lodash-es';
77
import { Subscription } from 'rxjs';
8-
import { bufferTime, debounceTime, filter } from 'rxjs/operators';
8+
import { debounceTime, filter } from 'rxjs/operators';
99

10-
import { ConnectionMetadata, MinigraphStatus, MyServersConfig } from '../config/connect.config.js';
10+
import { ConnectionMetadata, MinigraphStatus } from '../config/connect.config.js';
1111
import { EVENTS } from '../helper/nest-tokens.js';
1212

1313
interface MothershipWebsocketHeaders extends OutgoingHttpHeaders {
@@ -87,12 +87,10 @@ export class MothershipConnectionService implements OnModuleInit, OnModuleDestro
8787
filter((change) => Object.values(this.configKeys).includes(change.path)),
8888
// debouncing is necessary here (instead of buffering/batching) to prevent excess emissions
8989
// because the store.* config values will change frequently upon api boot
90-
// debounceTime(25)
91-
bufferTime(25)
90+
debounceTime(25)
9291
)
9392
.subscribe({
94-
next: (changes) => {
95-
this.logger.log(`changes: ${JSON.stringify(changes.map((c) => c.path))}`);
93+
next: () => {
9694
const { state } = this.getIdentityState();
9795
if (isEqual(state, this.lastIdentity)) {
9896
this.logger.debug('Identity unchanged; skipping event emission');

packages/unraid-api-plugin-connect/src/mothership-proxy/mothership.events.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import { EVENTS, GRAPHQL_PUBSUB_CHANNEL, GRAPHQL_PUBSUB_TOKEN } from '../helper/
99
import { MothershipConnectionService } from './connection.service.js';
1010
import { MothershipGraphqlClientService } from './graphql.client.js';
1111
import { MothershipSubscriptionHandler } from './mothership-subscription.handler.js';
12-
import { isEqual } from 'lodash-es';
1312

1413
@Injectable()
1514
export class MothershipHandler implements OnModuleDestroy {
1615
private readonly logger = new Logger(MothershipHandler.name);
17-
private isSettingUp = false;
1816
constructor(
1917
private readonly connectionService: MothershipConnectionService,
2018
private readonly clientService: MothershipGraphqlClientService,
@@ -37,25 +35,16 @@ export class MothershipHandler implements OnModuleDestroy {
3735
}
3836

3937
async setup() {
40-
// if (this.isSettingUp) {
41-
// this.logger.debug('Setup already in progress, skipping');
42-
// return;
43-
// }
44-
this.isSettingUp = true;
45-
try {
46-
await this.clear();
47-
const { state } = this.connectionService.getIdentityState();
48-
this.logger.verbose('cleared, got identity state');
49-
if (!state.apiKey) {
50-
this.logger.warn('No API key found; cannot setup mothership subscription');
51-
return;
52-
}
53-
await this.clientService.createClientInstance();
54-
await this.subscriptionHandler.subscribeToMothershipEvents();
55-
this.timeoutCheckerJob.start();
56-
} finally {
57-
this.isSettingUp = false;
38+
await this.clear();
39+
const { state } = this.connectionService.getIdentityState();
40+
this.logger.verbose('cleared, got identity state');
41+
if (!state.apiKey) {
42+
this.logger.warn('No API key found; cannot setup mothership subscription');
43+
return;
5844
}
45+
await this.clientService.createClientInstance();
46+
await this.subscriptionHandler.subscribeToMothershipEvents();
47+
this.timeoutCheckerJob.start();
5948
}
6049

6150
@OnEvent(EVENTS.IDENTITY_CHANGED, { async: true })

0 commit comments

Comments
 (0)