Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[json] when downloading JSON Schema files, do Conditional GETs #101050

Closed
madskristensen opened this issue Jun 25, 2020 · 7 comments
Closed

[json] when downloading JSON Schema files, do Conditional GETs #101050

madskristensen opened this issue Jun 25, 2020 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders json JSON support issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@madskristensen
Copy link
Contributor

The requests coming in for JSON Schema files to SchemaStore.org don't check if the remote files have changed before downloading them. This puts unneeded pressure on the SchemaStore.org servers and it downloads more data than needed which will cost money for users that pay bandwidth by the megabyte.

By supporting Conditional GETs (HTTP 304) using either If-Modified-Since or If-None-Match request header, these issues are fixed.

@aeschli aeschli added json JSON support issues feature-request Request for new features or functionality labels Jun 26, 2020
@aeschli aeschli added this to the Backlog milestone Jun 26, 2020
@aeschli aeschli changed the title When downloading JSON Schema files, do Conditional GETs [jspn] when downloading JSON Schema files, do Conditional GETs Jun 26, 2020
@aeschli aeschli changed the title [jspn] when downloading JSON Schema files, do Conditional GETs [json] when downloading JSON Schema files, do Conditional GETs Jun 26, 2020
@madskristensen
Copy link
Contributor Author

@aeschli I was hoping this could get a higher priority. I've gotten the VS team to prioritize this as well on their end. The reason is that I pay for server traffic and the free tier is no longer enough to handle the growing load from VS, VSCode and other editors.

@aeschli
Copy link
Contributor

aeschli commented Jun 29, 2020

I need to plan time for this, as it requires implementing http caching on the vscode/node side.
If you have any tips, let me know.

@madskristensen
Copy link
Contributor Author

Thanks. I understand.

One way to implement this could be this flow:

  1. VS Code was just installed. No cache exist yet
  2. User opens JSON file triggering a download of schema file
  3. Schema downloaded and HTTP Last-Modified response header is timestamped into the file when it was saved
  4. User opens the JSON file again within 7 days. VS Code never downloads new schemas if the current cached one is younger than 7 days (or however many days are appropriate for VS Code users)
  5. User opens JSON file again 10 days later, this time VSCode sends If-Modified-Since header containing the file's timestamp
  6. SchemaStore.org sends HTTP 304 Not Modified empty response because schema didn't have an update
  7. VS Code uses the schema on disk instead

You can send these headers using fetch from node.js and then check the HTTP status code from the response.

I believe this is the same conceptual pattern implemented by VS as well. Right @jimmylewis?

@jimmylewis
Copy link

Yes, that pretty much summarizes the VS implementation. Should note that:

  • for an expired local cache, we'll load the local copy, make the request, then reload JSON schema evaluation when we get a response. This keeps user responsiveness high for slow/flaky connections.
  • getting the 304 back should reset the local cache expiration for another 7 days. This minimizes bandwidth usage.
  • we also have a gesture to forcibly clear the local cache and force all schemas to download again the next time they are used.

@aeschli aeschli modified the milestones: Backlog, November 2021 Nov 16, 2021
@aeschli
Copy link
Contributor

aeschli commented Nov 19, 2021

I added a cache with a local cache expiration of 3 days (for now). After the cache expiration we check the content again with the last known etag.

@madskristensen
Copy link
Contributor Author

Thank you!! Much appreciated

@aeschli
Copy link
Contributor

aeschli commented Nov 29, 2021

To verify:

  • set "json.trace.server": "verbose"

  • open a JSON file with a schema. E.g package.json

  • open the JSON Langage Server output

  • in the output search for schema cache

  • schemas from http://json.schemastore.org are read 2 days from the cache. After that an etag is checked

  • all other schemas are read with etag

@aeschli aeschli added the verification-needed Verification of issue is requested label Nov 29, 2021
guibber pushed a commit to guibber/vscode that referenced this issue Nov 30, 2021
@tanhakabir tanhakabir added the verified Verification succeeded label Nov 30, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jan 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders json JSON support issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants
@madskristensen @jimmylewis @aeschli @tanhakabir and others