refactor: optimize delay between batches on mobile to allow UI interactivity during load (#2129)
This commit is contained in:
@@ -1581,6 +1581,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.identifier,
|
||||
{
|
||||
loadBatchSize: this.options.loadBatchSize,
|
||||
sleepBetweenBatches: this.options.sleepBetweenBatches,
|
||||
},
|
||||
this.internalEventBus,
|
||||
)
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { ApplicationSyncOptions } from './OptionalOptions'
|
||||
import { ApplicationDisplayOptions, ApplicationSyncOptions } from './OptionalOptions'
|
||||
|
||||
export interface ApplicationOptionsWhichHaveDefaults {
|
||||
loadBatchSize: ApplicationSyncOptions['loadBatchSize']
|
||||
sleepBetweenBatches: ApplicationSyncOptions['sleepBetweenBatches']
|
||||
allowNoteSelectionStatePersistence: ApplicationDisplayOptions['allowNoteSelectionStatePersistence']
|
||||
allowMultipleSelection: ApplicationDisplayOptions['allowMultipleSelection']
|
||||
}
|
||||
|
||||
export const ApplicationOptionsDefaults: ApplicationOptionsWhichHaveDefaults = {
|
||||
loadBatchSize: 700,
|
||||
sleepBetweenBatches: 10,
|
||||
allowMultipleSelection: true,
|
||||
allowNoteSelectionStatePersistence: true,
|
||||
}
|
||||
|
||||
@@ -3,10 +3,14 @@ export interface ApplicationSyncOptions {
|
||||
* The size of the item batch to decrypt and render upon application load.
|
||||
*/
|
||||
loadBatchSize: number
|
||||
|
||||
sleepBetweenBatches: number
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface ApplicationDisplayOptions {}
|
||||
export interface ApplicationDisplayOptions {
|
||||
allowNoteSelectionStatePersistence: boolean
|
||||
allowMultipleSelection: boolean
|
||||
}
|
||||
|
||||
export interface ApplicationOptionalConfiguratioOptions {
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AnyKeyParamsContent } from '@standardnotes/common'
|
||||
import { AnyKeyParamsContent, KeyParamsContent004 } from '@standardnotes/common'
|
||||
import { EncryptedPayload, EncryptedTransferPayload, isErrorDecryptingPayload } from '@standardnotes/models'
|
||||
import { PreviousSnjsVersion1_0_0, PreviousSnjsVersion2_0_0, SnjsVersion } from '../Version'
|
||||
import { Migration } from '@Lib/Migrations/Migration'
|
||||
@@ -165,7 +165,7 @@ export class BaseMigration extends Migration {
|
||||
}
|
||||
|
||||
private async repairMissingKeychain() {
|
||||
const rawAccountParams = await this.reader.getAccountKeyParams()
|
||||
const rawAccountParams = (await this.reader.getAccountKeyParams()) as AnyKeyParamsContent
|
||||
|
||||
/** Choose an item to decrypt against */
|
||||
const allItems = (
|
||||
@@ -196,14 +196,14 @@ export class BaseMigration extends Migration {
|
||||
ChallengeReason.Custom,
|
||||
false,
|
||||
KeychainRecoveryStrings.Title,
|
||||
KeychainRecoveryStrings.Text,
|
||||
KeychainRecoveryStrings.Text((rawAccountParams as KeyParamsContent004).identifier),
|
||||
)
|
||||
|
||||
return new Promise((resolve) => {
|
||||
this.services.challengeService.addChallengeObserver(challenge, {
|
||||
onNonvalidatedSubmit: async (challengeResponse) => {
|
||||
const password = challengeResponse.values[0].value as string
|
||||
const accountParams = this.services.protocolService.createKeyParams(rawAccountParams as AnyKeyParamsContent)
|
||||
const accountParams = this.services.protocolService.createKeyParams(rawAccountParams)
|
||||
const rootKey = await this.services.protocolService.computeRootKey(password, accountParams)
|
||||
|
||||
/** TS can't detect we returned early above if itemToDecrypt is null */
|
||||
|
||||
@@ -298,6 +298,9 @@ export class SNSyncService
|
||||
? chunks.fullEntries.remainingChunks
|
||||
: chunks.keys.remainingChunks
|
||||
|
||||
let chunkIndex = 0
|
||||
const ChunkIndexOfContentTypePriorityItems = 0
|
||||
|
||||
for (const chunk of remainingChunks) {
|
||||
const dbEntries = isChunkFullEntry(chunk)
|
||||
? chunk.entries
|
||||
@@ -314,7 +317,14 @@ export class SNSyncService
|
||||
.filter(isNotUndefined)
|
||||
|
||||
await this.processPayloadBatch(payloads, totalProcessedCount, payloadCount)
|
||||
|
||||
const shouldSleepOnlyAfterFirstRegularBatch = chunkIndex > ChunkIndexOfContentTypePriorityItems
|
||||
if (shouldSleepOnlyAfterFirstRegularBatch) {
|
||||
await sleep(this.options.sleepBetweenBatches, false, 'Sleeping to allow interface to update')
|
||||
}
|
||||
|
||||
totalProcessedCount += payloads.length
|
||||
chunkIndex++
|
||||
}
|
||||
|
||||
this.databaseLoaded = true
|
||||
@@ -353,8 +363,6 @@ export class SNSyncService
|
||||
if (currentPosition != undefined && payloadCount != undefined) {
|
||||
this.opStatus.setDatabaseLoadStatus(currentPosition, payloadCount, false)
|
||||
}
|
||||
|
||||
await sleep(1, false)
|
||||
}
|
||||
|
||||
private setLastSyncToken(token: string) {
|
||||
|
||||
Reference in New Issue
Block a user