Skip to content

Draft: feat: Settings sync cache proxy

Enrique Alcántara requested to merge settings-sync-cache into main

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:

  1. 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.
  2. GET /resource/:resource-name/:uuid It intercepts GET requests to a resource identified by an uuid . 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:

  1. Opens the Web IDE in the Chrome web browser and installs an extension.
  2. Closes Chrome.
  3. Opens the Web IDE in Firefox.
  4. The extension installed in Chrome will be installed in Firefox (correct behavior).
  5. Uninstalls the extension in Firefox and closes this web browser.
  6. Opens the Web IDE again in Chrome.
  7. 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:

  1. Opens the Web IDE in the Chrome web browser and changes the color theme.
  2. Closes Chrome.
  3. Opens the Web IDE in Firefox.
  4. The color theme applied in Chrome is also applied in Firefox (correct behavior).
  5. Changes the color theme in Firefox and closes this web browser.
  6. Opens the Web IDE again in Chrome.
  7. 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

settings_sync_before_720p.mov

settings_sync_after_720p.mov

Edited by Enrique Alcántara

Merge request reports