chore: global sync per minute safety limit (#2765)

This commit is contained in:
Karol Sójko
2024-01-11 15:26:09 +01:00
committed by GitHub
parent 3d895ca499
commit cf4b5ccf0a
11 changed files with 140 additions and 10 deletions

View File

@@ -176,11 +176,15 @@ import { Logger, isNotUndefined, isDeinitable, LoggerInterface } from '@standard
import { EncryptionOperators } from '@standardnotes/encryption'
import { AsymmetricMessagePayload, AsymmetricMessageSharedVaultInvite } from '@standardnotes/models'
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { SyncFrequencyGuard } from '@Lib/Services/Sync/SyncFrequencyGuard'
import { SyncFrequencyGuardInterface } from '@Lib/Services/Sync/SyncFrequencyGuardInterface'
export class Dependencies {
private factory = new Map<symbol, () => unknown>()
private dependencies = new Map<symbol, unknown>()
private DEFAULT_SYNC_CALLS_THRESHOLD_PER_MINUTE = 200
constructor(private options: FullyResolvedApplicationOptions) {
this.dependencies.set(TYPES.DeviceInterface, options.deviceInterface)
this.dependencies.set(TYPES.AlertService, options.alertService)
@@ -1341,6 +1345,12 @@ export class Dependencies {
)
})
this.factory.set(TYPES.SyncFrequencyGuard, () => {
return new SyncFrequencyGuard(
this.options.syncCallsThresholdPerMinute ?? this.DEFAULT_SYNC_CALLS_THRESHOLD_PER_MINUTE,
)
})
this.factory.set(TYPES.SyncService, () => {
return new SyncService(
this.get<ItemManager>(TYPES.ItemManager),
@@ -1358,6 +1368,7 @@ export class Dependencies {
},
this.get<Logger>(TYPES.Logger),
this.get<WebSocketsService>(TYPES.WebSocketsService),
this.get<SyncFrequencyGuardInterface>(TYPES.SyncFrequencyGuard),
this.get<InternalEventBus>(TYPES.InternalEventBus),
)
})

View File

@@ -29,6 +29,7 @@ export const TYPES = {
SessionManager: Symbol.for('SessionManager'),
SubscriptionManager: Symbol.for('SubscriptionManager'),
HistoryManager: Symbol.for('HistoryManager'),
SyncFrequencyGuard: Symbol.for('SyncFrequencyGuard'),
SyncService: Symbol.for('SyncService'),
ProtectionService: Symbol.for('ProtectionService'),
UserService: Symbol.for('UserService'),