Skip to content

Commit

Permalink
Merge branch 'main' into super-to-pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara authored Jan 23, 2024
2 parents 0cb486d + 813304c commit 49eaff7
Show file tree
Hide file tree
Showing 24 changed files with 166 additions and 9 deletions.
4 changes: 4 additions & 0 deletions packages/clipper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.396](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-23)

**Note:** Version bump only for package @standardnotes/clipper

## [1.1.395](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-21)

**Note:** Version bump only for package @standardnotes/clipper
Expand Down
2 changes: 1 addition & 1 deletion packages/clipper/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@standardnotes/clipper",
"description": "Web clipper browser extension for Standard Notes",
"version": "1.1.395",
"version": "1.1.396",
"private": true,
"scripts": {
"build-mv2": "yarn clean && webpack --config ./webpack.config.prod.js",
Expand Down
4 changes: 4 additions & 0 deletions packages/desktop/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [3.108.334](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-23)

**Note:** Version bump only for package @standardnotes/desktop

## [3.108.333](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-21)

**Note:** Version bump only for package @standardnotes/desktop
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@standardnotes/desktop",
"main": "./app/dist/index.js",
"version": "3.108.333",
"version": "3.108.334",
"license": "AGPL-3.0",
"author": "Standard Notes.",
"private": true,
Expand Down
4 changes: 4 additions & 0 deletions packages/mobile/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [3.58.55](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-23)

**Note:** Version bump only for package @standardnotes/mobile

## [3.58.54](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-21)

**Note:** Version bump only for package @standardnotes/mobile
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@standardnotes/mobile",
"version": "3.58.54",
"version": "3.58.55",
"author": "Standard Notes.",
"private": true,
"license": "AGPL-3.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/releases/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.4.690](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-23)

**Note:** Version bump only for package @standardnotes/releases

## [1.4.689](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-21)

**Note:** Version bump only for package @standardnotes/releases
Expand Down
2 changes: 1 addition & 1 deletion packages/releases/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@standardnotes/releases",
"version": "1.4.689",
"version": "1.4.690",
"license": "AGPL-3.0",
"main": "dist/releases.json",
"types": "dist/index.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions packages/services/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.68.1](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-23)

**Note:** Version bump only for package @standardnotes/services

# [1.68.0](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-20)

### Features
Expand Down
2 changes: 1 addition & 1 deletion packages/services/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@standardnotes/services",
"version": "1.68.0",
"version": "1.68.1",
"engines": {
"node": ">=16.0.0 <17.0.0"
},
Expand Down
55 changes: 55 additions & 0 deletions packages/services/src/Domain/Sync/SyncBackoffService.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { AnyItemInterface } from '@standardnotes/models'
import { SyncBackoffService } from './SyncBackoffService'

describe('SyncBackoffService', () => {
const createService = () => new SyncBackoffService()

it('should not be in backoff if no backoff was set', () => {
const service = createService()

expect(service.isItemInBackoff({ uuid: '123' } as jest.Mocked<AnyItemInterface>)).toBe(false)
})

it('should be in backoff if backoff was set', () => {
const service = createService()

service.backoffItem({ uuid: '123' } as jest.Mocked<AnyItemInterface>)

expect(service.isItemInBackoff({ uuid: '123' } as jest.Mocked<AnyItemInterface>)).toBe(true)
})

it('should not be in backoff if backoff expired', () => {
const service = createService()

jest.spyOn(Date, 'now').mockReturnValueOnce(1_000_000)

service.backoffItem({ uuid: '123' } as jest.Mocked<AnyItemInterface>)

jest.spyOn(Date, 'now').mockReturnValueOnce(2_000_000)

expect(service.isItemInBackoff({ uuid: '123' } as jest.Mocked<AnyItemInterface>)).toBe(false)
})

it('should double backoff penalty on each backoff', () => {
const service = createService()

jest.spyOn(Date, 'now').mockReturnValueOnce(1_000_000)

service.backoffItem({ uuid: '123' } as jest.Mocked<AnyItemInterface>)

jest.spyOn(Date, 'now').mockReturnValueOnce(1_000_000)
expect(service.isItemInBackoff({ uuid: '123' } as jest.Mocked<AnyItemInterface>)).toBe(true)

jest.spyOn(Date, 'now').mockReturnValueOnce(1_000_000)
service.backoffItem({ uuid: '123' } as jest.Mocked<AnyItemInterface>)

jest.spyOn(Date, 'now').mockReturnValueOnce(1_001_000)
expect(service.isItemInBackoff({ uuid: '123' } as jest.Mocked<AnyItemInterface>)).toBe(true)

jest.spyOn(Date, 'now').mockReturnValueOnce(1_000_000)
service.backoffItem({ uuid: '123' } as jest.Mocked<AnyItemInterface>)

jest.spyOn(Date, 'now').mockReturnValueOnce(1_003_000)
expect(service.isItemInBackoff({ uuid: '123' } as jest.Mocked<AnyItemInterface>)).toBe(true)
})
})
37 changes: 37 additions & 0 deletions packages/services/src/Domain/Sync/SyncBackoffService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AnyItemInterface } from '@standardnotes/models'
import { SyncBackoffServiceInterface } from './SyncBackoffServiceInterface'

export class SyncBackoffService implements SyncBackoffServiceInterface {
private backoffPenalties: Map<string, number>
private backoffStartTimestamps: Map<string, number>

constructor() {
this.backoffPenalties = new Map<string, number>()
this.backoffStartTimestamps = new Map<string, number>()
}

isItemInBackoff(item: AnyItemInterface): boolean {
const backoffStartingTimestamp = this.backoffStartTimestamps.get(item.uuid)
if (!backoffStartingTimestamp) {
return false
}

const backoffPenalty = this.backoffPenalties.get(item.uuid)
if (!backoffPenalty) {
return false
}

const backoffEndTimestamp = backoffStartingTimestamp + backoffPenalty

return backoffEndTimestamp > Date.now()
}

backoffItem(item: AnyItemInterface): void {
const backoffPenalty = this.backoffPenalties.get(item.uuid) || 0

const newBackoffPenalty = backoffPenalty === 0 ? 1_000 : backoffPenalty * 2

this.backoffPenalties.set(item.uuid, newBackoffPenalty)
this.backoffStartTimestamps.set(item.uuid, Date.now())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { AnyItemInterface } from '@standardnotes/models'

export interface SyncBackoffServiceInterface {
isItemInBackoff(item: AnyItemInterface): boolean
backoffItem(item: AnyItemInterface): void
}
2 changes: 2 additions & 0 deletions packages/services/src/Domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ export * from './Subscription/AppleIAPReceipt'
export * from './Subscription/SubscriptionManager'
export * from './Subscription/SubscriptionManagerEvent'
export * from './Subscription/SubscriptionManagerInterface'
export * from './Sync/SyncBackoffService'
export * from './Sync/SyncBackoffServiceInterface'
export * from './Sync/SyncMode'
export * from './Sync/SyncOpStatus'
export * from './Sync/SyncOptions'
Expand Down
4 changes: 4 additions & 0 deletions packages/snjs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.205.1](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-23)

**Note:** Version bump only for package @standardnotes/snjs

# [2.205.0](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-20)

### Features
Expand Down
7 changes: 7 additions & 0 deletions packages/snjs/lib/Application/Dependencies/Dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ import {
IsVaultAdmin,
IsReadonlyVaultMember,
DesignateSurvivor,
SyncBackoffService,
SyncBackoffServiceInterface,
} from '@standardnotes/services'
import { ItemManager } from '../../Services/Items/ItemManager'
import { PayloadManager } from '../../Services/Payloads/PayloadManager'
Expand Down Expand Up @@ -1351,6 +1353,10 @@ export class Dependencies {
)
})

this.factory.set(TYPES.SyncBackoffService, () => {
return new SyncBackoffService()
})

this.factory.set(TYPES.SyncService, () => {
return new SyncService(
this.get<ItemManager>(TYPES.ItemManager),
Expand All @@ -1369,6 +1375,7 @@ export class Dependencies {
this.get<Logger>(TYPES.Logger),
this.get<WebSocketsService>(TYPES.WebSocketsService),
this.get<SyncFrequencyGuardInterface>(TYPES.SyncFrequencyGuard),
this.get<SyncBackoffServiceInterface>(TYPES.SyncBackoffService),
this.get<InternalEventBus>(TYPES.InternalEventBus),
)
})
Expand Down
1 change: 1 addition & 0 deletions packages/snjs/lib/Application/Dependencies/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const TYPES = {
SubscriptionManager: Symbol.for('SubscriptionManager'),
HistoryManager: Symbol.for('HistoryManager'),
SyncFrequencyGuard: Symbol.for('SyncFrequencyGuard'),
SyncBackoffService: Symbol.for('SyncBackoffService'),
SyncService: Symbol.for('SyncService'),
ProtectionService: Symbol.for('ProtectionService'),
UserService: Symbol.for('UserService'),
Expand Down
8 changes: 7 additions & 1 deletion packages/snjs/lib/Services/Sync/SyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import {
ApplicationSyncOptions,
WebSocketsServiceEvent,
WebSocketsService,
SyncBackoffServiceInterface,
} from '@standardnotes/services'
import { OfflineSyncResponse } from './Offline/Response'
import {
Expand Down Expand Up @@ -171,6 +172,7 @@ export class SyncService
private logger: LoggerInterface,
private sockets: WebSocketsService,
private syncFrequencyGuard: SyncFrequencyGuardInterface,
private syncBackoffService: SyncBackoffServiceInterface,
protected override internalEventBus: InternalEventBusInterface,
) {
super(internalEventBus)
Expand Down Expand Up @@ -452,7 +454,11 @@ export class SyncService
}

private itemsNeedingSync() {
return this.itemManager.getDirtyItems()
const dirtyItems = this.itemManager.getDirtyItems()

const itemsWithoutBackoffPenalty = dirtyItems.filter((item) => !this.syncBackoffService.isItemInBackoff(item))

return itemsWithoutBackoffPenalty
}

public async markAllItemsAsNeedingSyncAndPersist(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/snjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@standardnotes/snjs",
"version": "2.205.0",
"version": "2.205.1",
"engines": {
"node": ">=16.0.0 <17.0.0"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/ui-services/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.35.21](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-23)

**Note:** Version bump only for package @standardnotes/ui-services

## [1.35.20](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-20)

**Note:** Version bump only for package @standardnotes/ui-services
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-services/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@standardnotes/ui-services",
"version": "1.35.20",
"version": "1.35.21",
"engines": {
"node": ">=16.0.0 <17.0.0"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [3.185.4](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-23)

**Note:** Version bump only for package @standardnotes/web

## [3.185.3](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-21)

**Note:** Version bump only for package @standardnotes/web
Expand Down
11 changes: 11 additions & 0 deletions packages/web/CHANGELOG.md.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{
"versions": [
{
"version": "3.185.4",
"title": "[3.185.4](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-23)",
"date": null,
"body": "**Note:** Version bump only for package @standardnotes/web",
"parsed": {
"_": [
"Note: Version bump only for package @standardnotes/web"
]
}
},
{
"version": "3.185.3",
"title": "[3.185.3](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2024-01-21)",
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@standardnotes/web",
"version": "3.185.3",
"version": "3.185.4",
"license": "AGPL-3.0",
"main": "dist/app.js",
"author": "Standard Notes",
Expand Down

0 comments on commit 49eaff7

Please sign in to comment.