Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Sync: Apply records asynchronously
Browse files Browse the repository at this point in the history
Fix brave/sync#44

Auditors: @diracdeltas

Test Plan:
1. Start Pyramid 1 which has a bunch of syncable data. Sync should enabled.
2. Setup Pyramid 2 (add `"start2": "node ./tools/start.js --user-data-dir=brave-development-2 --debug=5859 --enable-logging --v=0 --enable-extension-activity-logging --enable-sandbox-logging --enable-dcheck",` to package.json) and specify the Pyramid 1 Sync credentials.
3. When Pyramid 2 restarts and begins syncing data, Brave should be somewhat usable (not completely frozen for 60s).
  • Loading branch information
ayumi authored and diracdeltas committed Jan 27, 2017
1 parent 8bfc8fa commit 65a8764
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ module.exports.onSyncReady = (isFirstRun, e) => {
return
}
log(`applying resolved ${records.length} ${categoryName}.`)
for (let record of records) { syncUtil.applySyncRecord(record) }
syncUtil.applySyncRecords(records)
})
// Periodically poll for new records
let startAt = appState.getIn(['sync', 'lastFetchTimestamp']) || 0
Expand Down
13 changes: 13 additions & 0 deletions js/state/syncUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ module.exports.applySyncRecord = (record) => {
}
}

/**
* Apply several SyncRecords in a less blocking manner.
* @param {Array<Object>} records
*/
module.exports.applySyncRecords = (records) => {
if (!records || records.length === 0) { return }
setImmediate(() => {
const record = records.shift()
this.applySyncRecord(record)
this.applySyncRecords(records)
})
}

/**
* Given a category and SyncRecord, get an existing browser object.
* Used to respond to IPC GET_EXISTING_OBJECTS.
Expand Down

0 comments on commit 65a8764

Please sign in to comment.