Closed Bug 1454315 Opened 2 years ago Closed 2 years ago

Rename "change" event to "sync"

Categories

(Firefox :: Remote Settings Client, enhancement)

61 Branch
enhancement
Not set

Tracking

()

RESOLVED FIXED
Firefox 61
Tracking Status
firefox61 --- fixed

People

(Reporter: leplatrem, Assigned: leplatrem)

Details

Attachments

(1 file)

### on("sync", (e) => { ... })

The `on()` function registers handlers to be triggered when records changes on the server side.
Your handler is given an event object that contains a `.data` attribute that has information
about the changes.

Currently the only available event is `sync`.

```js
RemoteSettings("my-key").on("sync", (e) => {
   // e.data.current = [ Record, Record, ... ]
   // e.data.updated = [ Record, Record, ... ]
   // e.data.created = [ Record, Record, ... ]
   // e.data.deleted = [ Record, Record, ... ]
});
```

The `.data` attribute includes:

* `.data.current` - a list of the all records in your collection
* `.data.updated` - a list of the records updated by the sync
* `.data.created` - a list of the records that were added by the sync
* `.data.deleted` - a list of the records that were deleted by the sync
Assignee: nobody → mathieu
In my patch I did the following:
- split test_blocklist_clients.js and test_remote_settings.js
- updated the docs to mention the current/created/updated/deleted event attributes
- tested the sync event attributes in nominal cases (relying on kinto.js basically)
- tested the sync event attributes on signature verification retry when we clear the local and refetch the whole new content
Comment on attachment 8968873 [details]
Bug 1454315 - Introduce RemoteSettings sync event

https://reviewboard.mozilla.org/r/237588/#review244574

::: services/common/remote-settings.js:287
(Diff revision 5)
>            if (payload.last_modified >= localLastModified) {
> +            const { data: newData } = payload;
>              await collection.clear();
> -            await collection.loadDump(payload.data);
> +            await collection.loadDump(newData);
> +
> +            // Compare local and remote to populate the sync result

The intent of the original code here was to ensure that the collection is replaced with the remote version if the signature verification fails; this means that if user has corrupt (or modified) data, we can get back to a state where signatures are good. My reading of this code is that does something different?
Version: 57 Branch → 61 Branch
> My reading of this code is that does something different?

No it does not change the current behavior. It's just that after we cleared and replaced the local collection, we now build a sync result object.
It allows us to give the sync event listeners an event object that looks alike successful syncs.
Comment on attachment 8968873 [details]
Bug 1454315 - Introduce RemoteSettings sync event

https://reviewboard.mozilla.org/r/237588/#review246822
Attachment #8968873 - Flags: review?(mgoodwin) → review+
Keywords: checkin-needed
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/a6b22dcb5b80
Introduce RemoteSettings sync event r=mgoodwin
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/a6b22dcb5b80
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 61
You need to log in before you can comment on or make changes to this bug.