fix(syncing-server): remove the dice roll on whether to inform the client on items changed (#950)
This commit is contained in:
parent
3c10de3e5d
commit
589b740f49
4 changed files with 2 additions and 33 deletions
|
@ -114,13 +114,7 @@ import { GetSharedVaults } from '../Domain/UseCase/SharedVaults/GetSharedVaults/
|
||||||
import { CreateSharedVault } from '../Domain/UseCase/SharedVaults/CreateSharedVault/CreateSharedVault'
|
import { CreateSharedVault } from '../Domain/UseCase/SharedVaults/CreateSharedVault/CreateSharedVault'
|
||||||
import { DeleteSharedVault } from '../Domain/UseCase/SharedVaults/DeleteSharedVault/DeleteSharedVault'
|
import { DeleteSharedVault } from '../Domain/UseCase/SharedVaults/DeleteSharedVault/DeleteSharedVault'
|
||||||
import { CreateSharedVaultFileValetToken } from '../Domain/UseCase/SharedVaults/CreateSharedVaultFileValetToken/CreateSharedVaultFileValetToken'
|
import { CreateSharedVaultFileValetToken } from '../Domain/UseCase/SharedVaults/CreateSharedVaultFileValetToken/CreateSharedVaultFileValetToken'
|
||||||
import {
|
import { SharedVaultValetTokenData, TokenEncoder, TokenEncoderInterface } from '@standardnotes/security'
|
||||||
DeterministicSelector,
|
|
||||||
SelectorInterface,
|
|
||||||
SharedVaultValetTokenData,
|
|
||||||
TokenEncoder,
|
|
||||||
TokenEncoderInterface,
|
|
||||||
} from '@standardnotes/security'
|
|
||||||
import { SharedVaultHttpRepresentation } from '../Mapping/Http/SharedVaultHttpRepresentation'
|
import { SharedVaultHttpRepresentation } from '../Mapping/Http/SharedVaultHttpRepresentation'
|
||||||
import { SharedVaultHttpMapper } from '../Mapping/Http/SharedVaultHttpMapper'
|
import { SharedVaultHttpMapper } from '../Mapping/Http/SharedVaultHttpMapper'
|
||||||
import { SharedVaultInviteHttpRepresentation } from '../Mapping/Http/SharedVaultInviteHttpRepresentation'
|
import { SharedVaultInviteHttpRepresentation } from '../Mapping/Http/SharedVaultInviteHttpRepresentation'
|
||||||
|
@ -206,10 +200,6 @@ export class ContainerConfigLoader {
|
||||||
}
|
}
|
||||||
container.bind<winston.Logger>(TYPES.Sync_Logger).toConstantValue(logger)
|
container.bind<winston.Logger>(TYPES.Sync_Logger).toConstantValue(logger)
|
||||||
|
|
||||||
container
|
|
||||||
.bind<SelectorInterface<number>>(TYPES.Sync_NumberSelector)
|
|
||||||
.toConstantValue(new DeterministicSelector<number>())
|
|
||||||
|
|
||||||
const appDataSource = new AppDataSource({ env, runMigrations: this.mode === 'server' })
|
const appDataSource = new AppDataSource({ env, runMigrations: this.mode === 'server' })
|
||||||
await appDataSource.initialize()
|
await appDataSource.initialize()
|
||||||
|
|
||||||
|
@ -618,7 +608,6 @@ export class ContainerConfigLoader {
|
||||||
container.get<UpdateExistingItem>(TYPES.Sync_UpdateExistingItem),
|
container.get<UpdateExistingItem>(TYPES.Sync_UpdateExistingItem),
|
||||||
container.get<SendEventToClient>(TYPES.Sync_SendEventToClient),
|
container.get<SendEventToClient>(TYPES.Sync_SendEventToClient),
|
||||||
container.get<DomainEventFactoryInterface>(TYPES.Sync_DomainEventFactory),
|
container.get<DomainEventFactoryInterface>(TYPES.Sync_DomainEventFactory),
|
||||||
container.get<SelectorInterface<number>>(TYPES.Sync_NumberSelector),
|
|
||||||
container.get<Logger>(TYPES.Sync_Logger),
|
container.get<Logger>(TYPES.Sync_Logger),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,6 @@ const TYPES = {
|
||||||
Sync_SQS: Symbol.for('Sync_SQS'),
|
Sync_SQS: Symbol.for('Sync_SQS'),
|
||||||
Sync_S3: Symbol.for('Sync_S3'),
|
Sync_S3: Symbol.for('Sync_S3'),
|
||||||
Sync_Env: Symbol.for('Sync_Env'),
|
Sync_Env: Symbol.for('Sync_Env'),
|
||||||
Sync_NumberSelector: Symbol.for('Sync_NumberSelector'),
|
|
||||||
// Repositories
|
// Repositories
|
||||||
Sync_SQLItemRepository: Symbol.for('Sync_SQLItemRepository'),
|
Sync_SQLItemRepository: Symbol.for('Sync_SQLItemRepository'),
|
||||||
Sync_SharedVaultRepository: Symbol.for('Sync_SharedVaultRepository'),
|
Sync_SharedVaultRepository: Symbol.for('Sync_SharedVaultRepository'),
|
||||||
|
|
|
@ -11,7 +11,6 @@ import { Item } from '../../../Item/Item'
|
||||||
import { SendEventToClient } from '../SendEventToClient/SendEventToClient'
|
import { SendEventToClient } from '../SendEventToClient/SendEventToClient'
|
||||||
import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
|
import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
|
||||||
import { ItemsChangedOnServerEvent } from '@standardnotes/domain-events'
|
import { ItemsChangedOnServerEvent } from '@standardnotes/domain-events'
|
||||||
import { SelectorInterface } from '@standardnotes/security'
|
|
||||||
|
|
||||||
describe('SaveItems', () => {
|
describe('SaveItems', () => {
|
||||||
let itemSaveValidator: ItemSaveValidatorInterface
|
let itemSaveValidator: ItemSaveValidatorInterface
|
||||||
|
@ -24,7 +23,6 @@ describe('SaveItems', () => {
|
||||||
let savedItem: Item
|
let savedItem: Item
|
||||||
let sendEventToClient: SendEventToClient
|
let sendEventToClient: SendEventToClient
|
||||||
let domainEventFactory: DomainEventFactoryInterface
|
let domainEventFactory: DomainEventFactoryInterface
|
||||||
let deterministicSelector: SelectorInterface<number>
|
|
||||||
|
|
||||||
const createUseCase = () =>
|
const createUseCase = () =>
|
||||||
new SaveItems(
|
new SaveItems(
|
||||||
|
@ -35,14 +33,10 @@ describe('SaveItems', () => {
|
||||||
updateExistingItem,
|
updateExistingItem,
|
||||||
sendEventToClient,
|
sendEventToClient,
|
||||||
domainEventFactory,
|
domainEventFactory,
|
||||||
deterministicSelector,
|
|
||||||
logger,
|
logger,
|
||||||
)
|
)
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
deterministicSelector = {} as jest.Mocked<SelectorInterface<number>>
|
|
||||||
deterministicSelector.select = jest.fn().mockReturnValue(1)
|
|
||||||
|
|
||||||
sendEventToClient = {} as jest.Mocked<SendEventToClient>
|
sendEventToClient = {} as jest.Mocked<SendEventToClient>
|
||||||
sendEventToClient.execute = jest.fn().mockReturnValue(Result.ok())
|
sendEventToClient.execute = jest.fn().mockReturnValue(Result.ok())
|
||||||
|
|
||||||
|
@ -228,8 +222,6 @@ describe('SaveItems', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should update existing items', async () => {
|
it('should update existing items', async () => {
|
||||||
deterministicSelector.select = jest.fn().mockReturnValue(9)
|
|
||||||
|
|
||||||
const useCase = createUseCase()
|
const useCase = createUseCase()
|
||||||
|
|
||||||
itemRepository.findByUuid = jest.fn().mockResolvedValue(savedItem)
|
itemRepository.findByUuid = jest.fn().mockResolvedValue(savedItem)
|
||||||
|
@ -250,7 +242,7 @@ describe('SaveItems', () => {
|
||||||
sessionUuid: 'session-uuid',
|
sessionUuid: 'session-uuid',
|
||||||
performingUserUuid: '00000000-0000-0000-0000-000000000000',
|
performingUserUuid: '00000000-0000-0000-0000-000000000000',
|
||||||
})
|
})
|
||||||
expect(sendEventToClient.execute).not.toHaveBeenCalled()
|
expect(sendEventToClient.execute).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should mark items as conflicts if updating existing item fails', async () => {
|
it('should mark items as conflicts if updating existing item fails', async () => {
|
||||||
|
|
|
@ -13,7 +13,6 @@ import { UpdateExistingItem } from '../UpdateExistingItem/UpdateExistingItem'
|
||||||
import { ItemRepositoryInterface } from '../../../Item/ItemRepositoryInterface'
|
import { ItemRepositoryInterface } from '../../../Item/ItemRepositoryInterface'
|
||||||
import { SendEventToClient } from '../SendEventToClient/SendEventToClient'
|
import { SendEventToClient } from '../SendEventToClient/SendEventToClient'
|
||||||
import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
|
import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
|
||||||
import { SelectorInterface } from '@standardnotes/security'
|
|
||||||
|
|
||||||
export class SaveItems implements UseCaseInterface<SaveItemsResult> {
|
export class SaveItems implements UseCaseInterface<SaveItemsResult> {
|
||||||
private readonly SYNC_TOKEN_VERSION = 2
|
private readonly SYNC_TOKEN_VERSION = 2
|
||||||
|
@ -26,7 +25,6 @@ export class SaveItems implements UseCaseInterface<SaveItemsResult> {
|
||||||
private updateExistingItem: UpdateExistingItem,
|
private updateExistingItem: UpdateExistingItem,
|
||||||
private sendEventToClient: SendEventToClient,
|
private sendEventToClient: SendEventToClient,
|
||||||
private domainEventFactory: DomainEventFactoryInterface,
|
private domainEventFactory: DomainEventFactoryInterface,
|
||||||
private deterministicSelector: SelectorInterface<number>,
|
|
||||||
private logger: Logger,
|
private logger: Logger,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@ -157,15 +155,6 @@ export class SaveItems implements UseCaseInterface<SaveItemsResult> {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const tenPercentSpreadArray = Array.from(Array(10).keys())
|
|
||||||
const diceRoll = this.deterministicSelector.select(dto.userUuid, tenPercentSpreadArray)
|
|
||||||
if (diceRoll > 6) {
|
|
||||||
this.logger.debug(`[${dto.userUuid}] Not sending items changed event to client.`)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.logger.debug(`[${dto.userUuid}] Sending items changed event to client.`)
|
|
||||||
|
|
||||||
const itemsChangedEvent = this.domainEventFactory.createItemsChangedOnServerEvent({
|
const itemsChangedEvent = this.domainEventFactory.createItemsChangedOnServerEvent({
|
||||||
userUuid: dto.userUuid,
|
userUuid: dto.userUuid,
|
||||||
sessionUuid: dto.sessionUuid,
|
sessionUuid: dto.sessionUuid,
|
||||||
|
|
Loading…
Reference in a new issue