Draft: feat: Settings sync cache proxy
What does this MR do?
It implements a service worker that proxies requests to the Settings Sync REST API. The service worker intercepts two Settings Sync endpoints:
- POST
/resource/:resource-name
It intercepts POST requests to create a resource and stores the resource's content in an IndexedBD database identified by the UUID generated by the server. - GET
/resource/:resource-name/:uuid
It intercepts GET requests to a resource identified by anuuid
. If the resource is cached in the IndexedDB database, it is returned from the cache rather than requesting it from the REST API.
Why?
We made the design decision of storing a single resource snapshot per user per resource type in the backend to avoid having a significant impact on the database speed and size. For example, If client A saves a resource of type extensions
by sending a POST request to the API, and later, client B does the same, client A's resource will be overwritten in the backend.
We identified a bug caused by this restriction. VSCode's Settings Sync client expects that the backend API will store, at least, the latest resource sent by a client. If the client obtains an empty response for a resource that it previously stored in the backend, it will assume that the resource was never sent to the server and it won't apply the latest changes stored in the backend.
The effects of this bug vary across resources. I will provide two examples for the most important resource types: extensions
and settings
.
Extensions
The user follows these steps:
- Opens the Web IDE in the Chrome web browser and installs an extension.
- Closes Chrome.
- Opens the Web IDE in Firefox.
- The extension installed in Chrome will be installed in Firefox (correct behavior).
- Uninstalls the extension in Firefox and closes this web browser.
- Opens the Web IDE again in Chrome.
- The uninstalled extension is not uninstalled in Chrome, instead, it is registered as "Installed" again (wrong behavior).
The correct behavior is that the extension is also uninstalled in Chrome.
Settings
The user follows these steps:
- Opens the Web IDE in the Chrome web browser and changes the color theme.
- Closes Chrome.
- Opens the Web IDE in Firefox.
- The color theme applied in Chrome is also applied in Firefox (correct behavior).
- Changes the color theme in Firefox and closes this web browser.
- Opens the Web IDE again in Chrome.
- The previously applied theme is still applied in Chrome and it is stored again in the backend (wrong behavior).
The correct behavior is that the theme applied in Firefox is also applied in Chrome.
Demo
Before | After |
---|---|