chore: global sync per minute safety limit (#2765)
This commit is contained in:
@@ -97,6 +97,7 @@ import {
|
||||
import { CreatePayloadFromRawServerItem } from './Account/Utilities'
|
||||
import { DecryptedServerConflictMap, TrustedServerConflictMap } from './Account/ServerConflictMap'
|
||||
import { ContentType } from '@standardnotes/domain-core'
|
||||
import { SyncFrequencyGuardInterface } from './SyncFrequencyGuardInterface'
|
||||
|
||||
const DEFAULT_MAJOR_CHANGE_THRESHOLD = 15
|
||||
const INVALID_SESSION_RESPONSE_STATUS = 401
|
||||
@@ -169,6 +170,7 @@ export class SyncService
|
||||
private readonly options: ApplicationSyncOptions,
|
||||
private logger: LoggerInterface,
|
||||
private sockets: WebSocketsService,
|
||||
private syncFrequencyGuard: SyncFrequencyGuardInterface,
|
||||
protected override internalEventBus: InternalEventBusInterface,
|
||||
) {
|
||||
super(internalEventBus)
|
||||
@@ -643,7 +645,8 @@ export class SyncService
|
||||
const syncInProgress = this.opStatus.syncInProgress
|
||||
const databaseLoaded = this.databaseLoaded
|
||||
const canExecuteSync = !this.syncLock
|
||||
const shouldExecuteSync = canExecuteSync && databaseLoaded && !syncInProgress
|
||||
const syncLimitReached = this.syncFrequencyGuard.isSyncCallsThresholdReachedThisMinute()
|
||||
const shouldExecuteSync = canExecuteSync && databaseLoaded && !syncInProgress && !syncLimitReached
|
||||
|
||||
if (shouldExecuteSync) {
|
||||
this.syncLock = true
|
||||
@@ -1296,6 +1299,8 @@ export class SyncService
|
||||
|
||||
this.lastSyncDate = new Date()
|
||||
|
||||
this.syncFrequencyGuard.incrementCallsPerMinute()
|
||||
|
||||
if (operation instanceof AccountSyncOperation && operation.numberOfItemsInvolved >= this.majorChangeThreshold) {
|
||||
void this.notifyEvent(SyncEvent.MajorDataChange)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user