-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Use new translation system #190
Conversation
👋 Thanks for opening a pull request!If you are new, please check out the trimmed down summary of our deployment process below:
Please note, if you have a more complex change, it is advised to claim a deployment lock with Once your PR has been merged, you can remove the lock with |
.deploy to development |
Deployment Triggered 🚀Razzmatazzz, started a branch deployment to development You can watch the progress here 🔗
|
API Deployment - Development 🪐The API has been deployed to the development environment 🚀
|
Deployment Results ✅Razzmatazzz successfully deployed branch
|
.deploy |
Deployment Triggered 🚀Razzmatazzz, started a branch deployment to production You can watch the progress here 🔗
|
API Deployment - Production 🌔The API has been deployed to the production environment 🚀
|
Deployment Results ✅Razzmatazzz successfully deployed branch
|
Why not save the |
Each request has its own context, and part of that context is the requestId assigned to the request. Initializing the KVs using the requestId is necessary to avoid hanging promises. None of this is changed behavior from how the API previously worked; just instead of initializing using the requestId, it passes the context object which includes the requestId. |
.deploy |
Deployment Triggered 🚀Razzmatazzz, started a branch deployment to production You can watch the progress here 🔗
|
API Deployment - Production 🌔The API has been deployed to the production environment 🚀
|
Deployment Results ✅Razzmatazzz successfully deployed branch
|
Exactly, so why not assign the something like this:
|
Because that worker class is instantiated once for each KV we use. But a worker can respond to multiple requests simultaneously. If the worker saves every context it receives to a single variable, it will end up calling getLocale using the wrong context for some requests. |
To expand on this a bit more: The overall cloudflare worker has a "data store" that basically consists of multiple instances of the WorkerKV object, one instance for each KV used in the API. With the cloudflare worker keeping one copy of each KV for its entire runtime, we eliminate duplicate unnecessary KV reads. Once a particular KV is read, the worker holds the result in memory until that data is considered stale, and then it reads the KV again. So each cloudflare worker only reads the KVs as often as absolutely necessary. When the cloudflare worker receives a new API request, it assigns that request a unique ID, and assigns that request ID to the context object that the GraphQL library uses (and that is available when resolving GraphQL queries). The "data store" of WorkerKV object instances is also added to the context for each request. When GraphQL is resolving a query, the WorkerKV objects use the request ID from the context object to track which requests are responsible for triggering an initial read of the KV data (if necessary). Each GraphQL query will also potentially be made in a different language. So if the context object for a request is saved to the WorkerKV object, there is no guarantee that the correct context object will be available at that variable later in code execution. A subsequent request may have overwritten it. |
Good explanation, thank you, I also now see that |
I should probably add comments that explain what's going on to help with maintainability. If I approached this repo fresh, there is a lot of stuff I'd think could be done differently and more efficiently but would actually cause errors due to the unique behavior of Cloudflare workers. |
Should be deployed to production in conjunction with the matching data manager PR. Changes the way translations are handled to save space and make it easier to get a list of which strings we use.