зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1433178 p2 - Allow callers to SyncedBookmarksMirror.apply() to pass explicit weak uploads. r=kitcambridge
MozReview-Commit-ID: EqVmk7AqHWS --HG-- extra : rebase_source : e4c93aa30f66a8313e5e372b35e929b1472227c6
This commit is contained in:
Родитель
89405d6bba
Коммит
b2cd60e2b5
|
@ -727,7 +727,9 @@ BufferedBookmarksEngine.prototype = {
|
||||||
let buf = await this._store.ensureOpenMirror();
|
let buf = await this._store.ensureOpenMirror();
|
||||||
let recordsToUpload = await buf.apply({
|
let recordsToUpload = await buf.apply({
|
||||||
remoteTimeSeconds: Resource.serverTime,
|
remoteTimeSeconds: Resource.serverTime,
|
||||||
|
weakUpload: [...this._needWeakUpload.keys()],
|
||||||
});
|
});
|
||||||
|
this._needWeakUpload.clear();
|
||||||
this._modified.replace(recordsToUpload);
|
this._modified.replace(recordsToUpload);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -736,9 +738,6 @@ BufferedBookmarksEngine.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async _createRecord(id) {
|
async _createRecord(id) {
|
||||||
if (this._needWeakUpload.has(id)) {
|
|
||||||
return this._store.createRecord(id, this.name);
|
|
||||||
}
|
|
||||||
let change = this._modified.changes[id];
|
let change = this._modified.changes[id];
|
||||||
if (!change) {
|
if (!change) {
|
||||||
this._log.error("Creating record for item ${id} not in strong " +
|
this._log.error("Creating record for item ${id} not in strong " +
|
||||||
|
|
|
@ -310,14 +310,17 @@ class SyncedBookmarksMirror {
|
||||||
* The current local time, in seconds.
|
* The current local time, in seconds.
|
||||||
* @param {Number} [options.remoteTimeSeconds]
|
* @param {Number} [options.remoteTimeSeconds]
|
||||||
* The current server time, in seconds.
|
* The current server time, in seconds.
|
||||||
|
* @param {String[]} [options.weakUpload]
|
||||||
|
* GUIDs of bookmarks to weakly upload.
|
||||||
* @return {Object.<String, BookmarkChangeRecord>}
|
* @return {Object.<String, BookmarkChangeRecord>}
|
||||||
* A changeset containing locally changed and reconciled records to
|
* A changeset containing locally changed and reconciled records to
|
||||||
* upload to the server, and to store in the mirror once upload
|
* upload to the server, and to store in the mirror once upload
|
||||||
* succeeds.
|
* succeeds.
|
||||||
*/
|
*/
|
||||||
async apply({ localTimeSeconds = Date.now() / 1000,
|
async apply({ localTimeSeconds = Date.now() / 1000,
|
||||||
remoteTimeSeconds = 0 } = {}) {
|
remoteTimeSeconds = 0,
|
||||||
let hasChanges = await this.hasChanges();
|
weakUpload = [] } = {}) {
|
||||||
|
let hasChanges = weakUpload.length > 0 || (await this.hasChanges());
|
||||||
if (!hasChanges) {
|
if (!hasChanges) {
|
||||||
MirrorLog.debug("No changes detected in both mirror and Places");
|
MirrorLog.debug("No changes detected in both mirror and Places");
|
||||||
return {};
|
return {};
|
||||||
|
@ -425,7 +428,7 @@ class SyncedBookmarksMirror {
|
||||||
await this.noteObserverChanges(observersToNotify);
|
await this.noteObserverChanges(observersToNotify);
|
||||||
|
|
||||||
MirrorLog.debug("Staging locally changed items for upload");
|
MirrorLog.debug("Staging locally changed items for upload");
|
||||||
await this.stageItemsToUpload();
|
await this.stageItemsToUpload(weakUpload);
|
||||||
|
|
||||||
MirrorLog.debug("Fetching records for local items to upload");
|
MirrorLog.debug("Fetching records for local items to upload");
|
||||||
let changeRecords = await this.fetchLocalChangeRecords();
|
let changeRecords = await this.fetchLocalChangeRecords();
|
||||||
|
@ -1472,8 +1475,21 @@ class SyncedBookmarksMirror {
|
||||||
* items. The change counter in Places is the persistent record of items that
|
* items. The change counter in Places is the persistent record of items that
|
||||||
* we need to upload, so, if upload is interrupted or fails, we'll stage the
|
* we need to upload, so, if upload is interrupted or fails, we'll stage the
|
||||||
* items again on the next sync.
|
* items again on the next sync.
|
||||||
|
*
|
||||||
|
* @param {String[]} weakUpload
|
||||||
|
* GUIDs of bookmarks to weakly upload.
|
||||||
*/
|
*/
|
||||||
async stageItemsToUpload() {
|
async stageItemsToUpload(weakUpload) {
|
||||||
|
// Stage explicit weak uploads such as repair responses.
|
||||||
|
for (let chunk of PlacesSyncUtils.chunkArray(weakUpload,
|
||||||
|
SQLITE_MAX_VARIABLE_NUMBER)) {
|
||||||
|
await this.db.execute(`
|
||||||
|
INSERT INTO itemsToWeaklyReupload(id)
|
||||||
|
SELECT b.id FROM moz_bookmarks b
|
||||||
|
WHERE b.guid IN (${new Array(chunk.length).fill("?").join(",")})`,
|
||||||
|
chunk);
|
||||||
|
}
|
||||||
|
|
||||||
// Stage remotely changed items with older local creation dates. These are
|
// Stage remotely changed items with older local creation dates. These are
|
||||||
// tracked "weakly": if the upload is interrupted or fails, we won't
|
// tracked "weakly": if the upload is interrupted or fails, we won't
|
||||||
// reupload the record on the next sync.
|
// reupload the record on the next sync.
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
add_task(async function test_explicit_weakupload() {
|
||||||
|
let buf = await openMirror("weakupload");
|
||||||
|
|
||||||
|
await PlacesUtils.bookmarks.insertTree({
|
||||||
|
guid: PlacesUtils.bookmarks.menuGuid,
|
||||||
|
children: [{
|
||||||
|
guid: "mozBmk______",
|
||||||
|
url: "https://mozilla.org",
|
||||||
|
title: "Mozilla",
|
||||||
|
tags: ["moz", "dot", "org"],
|
||||||
|
}],
|
||||||
|
});
|
||||||
|
await buf.store(shuffle([{
|
||||||
|
id: "menu",
|
||||||
|
type: "folder",
|
||||||
|
children: ["mozBmk______"],
|
||||||
|
}, {
|
||||||
|
id: "mozBmk______",
|
||||||
|
type: "bookmark",
|
||||||
|
title: "Mozilla",
|
||||||
|
bmkUri: "https://mozilla.org",
|
||||||
|
tags: ["moz", "dot", "org"],
|
||||||
|
}]), { needsMerge: false });
|
||||||
|
await PlacesTestUtils.markBookmarksAsSynced();
|
||||||
|
|
||||||
|
let changesToUpload = await buf.apply({
|
||||||
|
weakUpload: ["mozBmk______"]
|
||||||
|
});
|
||||||
|
|
||||||
|
ok("mozBmk______" in changesToUpload);
|
||||||
|
equal(changesToUpload.mozBmk______.counter, 0);
|
||||||
|
|
||||||
|
await buf.finalize();
|
||||||
|
await PlacesUtils.bookmarks.eraseEverything();
|
||||||
|
await PlacesSyncUtils.bookmarks.reset();
|
||||||
|
});
|
|
@ -8,6 +8,7 @@ support-files =
|
||||||
[test_bookmark_corruption.js]
|
[test_bookmark_corruption.js]
|
||||||
[test_bookmark_deduping.js]
|
[test_bookmark_deduping.js]
|
||||||
[test_bookmark_deletion.js]
|
[test_bookmark_deletion.js]
|
||||||
|
[test_bookmark_explicit_weakupload.js]
|
||||||
[test_bookmark_haschanges.js]
|
[test_bookmark_haschanges.js]
|
||||||
[test_bookmark_kinds.js]
|
[test_bookmark_kinds.js]
|
||||||
[test_bookmark_structure_changes.js]
|
[test_bookmark_structure_changes.js]
|
||||||
|
|
Загрузка…
Ссылка в новой задаче