mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1528979 - Fix loading of empty JSON dump in Remote Settings r=glasserc
Fix loading of empty JSON dump Storing an empty JSON dump should prevent .get() to initiate a sync. Differential Revision: https://phabricator.services.mozilla.com/D20352 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
4b13e47e2f
commit
6192972883
@ -65,9 +65,7 @@ const Agent = {
|
||||
*/
|
||||
async importJSONDump(bucket, collection) {
|
||||
const { data: records } = await loadJSONDump(bucket, collection);
|
||||
if (records.length > 0) {
|
||||
await importDumpIDB(bucket, collection, records);
|
||||
}
|
||||
await importDumpIDB(bucket, collection, records);
|
||||
return records.length;
|
||||
},
|
||||
};
|
||||
@ -140,8 +138,8 @@ async function importDumpIDB(bucket, collection, records) {
|
||||
}
|
||||
});
|
||||
|
||||
// Store the highest timestamp as the collection timestamp.
|
||||
const timestamp = Math.max(...records.map(record => record.last_modified));
|
||||
// Store the highest timestamp as the collection timestamp (or zero if dump is empty).
|
||||
const timestamp = records.length === 0 ? 0 : Math.max(...records.map(record => record.last_modified));
|
||||
await executeIDB(db, IDB_TIMESTAMPS_STORE, store => store.put({ cid, value: timestamp }));
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.j
|
||||
const IS_ANDROID = AppConstants.platform == "android";
|
||||
|
||||
const { RemoteSettings } = ChromeUtils.import("resource://services-settings/remote-settings.js");
|
||||
const { Utils } = ChromeUtils.import("resource://services-settings/Utils.jsm");
|
||||
const { UptakeTelemetry } = ChromeUtils.import("resource://services-common/uptake-telemetry.js");
|
||||
|
||||
const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
|
||||
@ -133,6 +134,21 @@ add_task(async function test_get_loads_default_records_from_a_local_dump_when_da
|
||||
});
|
||||
add_task(clear_state);
|
||||
|
||||
add_task(async function test_get_does_not_sync_if_empty_dump_is_provided() {
|
||||
if (IS_ANDROID) {
|
||||
// Skip test: we don't ship remote settings dumps on Android (see package-manifest).
|
||||
return;
|
||||
}
|
||||
|
||||
const clientWithEmptyDump = RemoteSettings("example");
|
||||
Assert.ok(!(await Utils.hasLocalData(clientWithEmptyDump)));
|
||||
|
||||
const data = await clientWithEmptyDump.get();
|
||||
|
||||
equal(data.length, 0);
|
||||
Assert.ok(await Utils.hasLocalData(clientWithEmptyDump));
|
||||
});
|
||||
|
||||
add_task(async function test_get_triggers_synchronization_when_database_is_empty() {
|
||||
// The "password-fields" collection has no local dump, and no local data.
|
||||
// Therefore a synchronization will happen.
|
||||
|
Loading…
Reference in New Issue
Block a user