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 { DeleteSharedVault } from '../Domain/UseCase/SharedVaults/DeleteSharedVault/DeleteSharedVault'
|
||||
import { CreateSharedVaultFileValetToken } from '../Domain/UseCase/SharedVaults/CreateSharedVaultFileValetToken/CreateSharedVaultFileValetToken'
|
||||
import {
|
||||
DeterministicSelector,
|
||||
SelectorInterface,
|
||||
SharedVaultValetTokenData,
|
||||
TokenEncoder,
|
||||
TokenEncoderInterface,
|
||||
} from '@standardnotes/security'
|
||||
import { SharedVaultValetTokenData, TokenEncoder, TokenEncoderInterface } from '@standardnotes/security'
|
||||
import { SharedVaultHttpRepresentation } from '../Mapping/Http/SharedVaultHttpRepresentation'
|
||||
import { SharedVaultHttpMapper } from '../Mapping/Http/SharedVaultHttpMapper'
|
||||
import { SharedVaultInviteHttpRepresentation } from '../Mapping/Http/SharedVaultInviteHttpRepresentation'
|
||||
|
@ -206,10 +200,6 @@ export class ContainerConfigLoader {
|
|||
}
|
||||
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' })
|
||||
await appDataSource.initialize()
|
||||
|
||||
|
@ -618,7 +608,6 @@ export class ContainerConfigLoader {
|
|||
container.get<UpdateExistingItem>(TYPES.Sync_UpdateExistingItem),
|
||||
container.get<SendEventToClient>(TYPES.Sync_SendEventToClient),
|
||||
container.get<DomainEventFactoryInterface>(TYPES.Sync_DomainEventFactory),
|
||||
container.get<SelectorInterface<number>>(TYPES.Sync_NumberSelector),
|
||||
container.get<Logger>(TYPES.Sync_Logger),
|
||||
),
|
||||
)
|
||||
|
|
|
@ -6,7 +6,6 @@ const TYPES = {
|
|||
Sync_SQS: Symbol.for('Sync_SQS'),
|
||||
Sync_S3: Symbol.for('Sync_S3'),
|
||||
Sync_Env: Symbol.for('Sync_Env'),
|
||||
Sync_NumberSelector: Symbol.for('Sync_NumberSelector'),
|
||||
// Repositories
|
||||
Sync_SQLItemRepository: Symbol.for('Sync_SQLItemRepository'),
|
||||
Sync_SharedVaultRepository: Symbol.for('Sync_SharedVaultRepository'),
|
||||
|
|
|
@ -11,7 +11,6 @@ import { Item } from '../../../Item/Item'
|
|||
import { SendEventToClient } from '../SendEventToClient/SendEventToClient'
|
||||
import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
|
||||
import { ItemsChangedOnServerEvent } from '@standardnotes/domain-events'
|
||||
import { SelectorInterface } from '@standardnotes/security'
|
||||
|
||||
describe('SaveItems', () => {
|
||||
let itemSaveValidator: ItemSaveValidatorInterface
|
||||
|
@ -24,7 +23,6 @@ describe('SaveItems', () => {
|
|||
let savedItem: Item
|
||||
let sendEventToClient: SendEventToClient
|
||||
let domainEventFactory: DomainEventFactoryInterface
|
||||
let deterministicSelector: SelectorInterface<number>
|
||||
|
||||
const createUseCase = () =>
|
||||
new SaveItems(
|
||||
|
@ -35,14 +33,10 @@ describe('SaveItems', () => {
|
|||
updateExistingItem,
|
||||
sendEventToClient,
|
||||
domainEventFactory,
|
||||
deterministicSelector,
|
||||
logger,
|
||||
)
|
||||
|
||||
beforeEach(() => {
|
||||
deterministicSelector = {} as jest.Mocked<SelectorInterface<number>>
|
||||
deterministicSelector.select = jest.fn().mockReturnValue(1)
|
||||
|
||||
sendEventToClient = {} as jest.Mocked<SendEventToClient>
|
||||
sendEventToClient.execute = jest.fn().mockReturnValue(Result.ok())
|
||||
|
||||
|
@ -228,8 +222,6 @@ describe('SaveItems', () => {
|
|||
})
|
||||
|
||||
it('should update existing items', async () => {
|
||||
deterministicSelector.select = jest.fn().mockReturnValue(9)
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
itemRepository.findByUuid = jest.fn().mockResolvedValue(savedItem)
|
||||
|
@ -250,7 +242,7 @@ describe('SaveItems', () => {
|
|||
sessionUuid: 'session-uuid',
|
||||
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 () => {
|
||||
|
|
|
@ -13,7 +13,6 @@ import { UpdateExistingItem } from '../UpdateExistingItem/UpdateExistingItem'
|
|||
import { ItemRepositoryInterface } from '../../../Item/ItemRepositoryInterface'
|
||||
import { SendEventToClient } from '../SendEventToClient/SendEventToClient'
|
||||
import { DomainEventFactoryInterface } from '../../../Event/DomainEventFactoryInterface'
|
||||
import { SelectorInterface } from '@standardnotes/security'
|
||||
|
||||
export class SaveItems implements UseCaseInterface<SaveItemsResult> {
|
||||
private readonly SYNC_TOKEN_VERSION = 2
|
||||
|
@ -26,7 +25,6 @@ export class SaveItems implements UseCaseInterface<SaveItemsResult> {
|
|||
private updateExistingItem: UpdateExistingItem,
|
||||
private sendEventToClient: SendEventToClient,
|
||||
private domainEventFactory: DomainEventFactoryInterface,
|
||||
private deterministicSelector: SelectorInterface<number>,
|
||||
private logger: Logger,
|
||||
) {}
|
||||
|
||||
|
@ -157,15 +155,6 @@ export class SaveItems implements UseCaseInterface<SaveItemsResult> {
|
|||
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({
|
||||
userUuid: dto.userUuid,
|
||||
sessionUuid: dto.sessionUuid,
|
||||
|
|
Loading…
Reference in a new issue