-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: Translation Api #515
Conversation
I can't remember whats the rationale for omitting the actual translated value (called |
* start writing unit tests * error handling for missing translation * fix error in sql query
Yes the reason is so that when you edit the translated value, the |
* fix logic error when `put` * handle unexisting key in the indexing (by creating a new Set) * make `fieldRef` and `regionCode` optional when `get`
I'm wondering how are we actually using the cache (when calling Map(1) { 'es' => Set(1) { 'field' } } Which signals that basically we have fields translated to spanish. I would think that we would use this Map on subsequent calls to |
Now that I think about it, shouldn't the Map<languageCode,Map<schemaName,Map<fieldRef,message>>> I know that it looks convoluted, but that way we're actually storing the translated values in memory that we can retrieve |
In get(opts) {
const docTypeIsTranslatedToLanguage = this.#translatedLanguageCodeToSchemaNames.get(opts.languageCode)?.has(opts.schemaNameRef)
if (! docTypeIsTranslatedToLanguage) return [] The vast majority of records in the database will not have any translation. This provides a shortcut to avoid an unnecessary database query, with a fairly small memory footprint (the size of this map is limited to the number of languages the user has translated for, by the number of schema types they have translated, so fairly small). |
owww ok yeah, that makes sense; its not to cache records, is to avoid queries for things we don't have translation for. I kinda knew that after our sync, but I guess I just forgot |
Shouldn't the |
* expose cache map through symbol and getter * improve `get` signature (by making `fieldRef` and `regionCode` optional) * add more unit tests
I took the liberty of setting |
You're missing that there is more than one user/writer in a project 🙂 |
HEh! That's what I was missing. I'll revert that and update the tests |
* add translationDoc to entries for batching indexer * move decoding of translationDoc into `.index` function in translationApi
…ranslationApi Also, have a fallback when no matching `regionCode` (can be reverted is it not desired)
src/translation-api.js
Outdated
if (doc) { | ||
await this.#dataType.update(doc.versionId, value) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (doc) { | |
await this.#dataType.update(doc.versionId, value) | |
} | |
await this.#dataType.update(doc.versionId, value) |
src/translation-api.js
Outdated
// @ts-ignore how can this be improved (we can maybe set "useUnknownInCatchVariables": false) | ||
if (e.message !== 'Not found') | ||
throw new Error(`Error on translation ${e}`) | ||
// TODO: throw if the error is different from 'Not found' | ||
return await this.#dataType[kCreateWithDocId](docId, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines have several issues, which (I think) I fixed in #590.
Co-authored-by: Evan Hahn <me@evanhahn.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for addressing all of my comments!
…ext into feat/translationApi
this should close #466