Initial implementation of whereEq queries#79
Conversation
b3593b9 to
cde08c7
Compare
e31dadb to
3722107
Compare
| dict: dict<'val>, | ||
| dict: Js.Dict.t<'val>, |
There was a problem hiding this comment.
Note to revert back to dict
DZakh
left a comment
There was a problem hiding this comment.
Reviewed everything besides codegenerator/cli/templates/static/codegen/src/InMemoryTable.res
I'll continue tomorrow morning. Looks good so far
| switch (a, b) { | ||
| //For big decimal use custom equals operator otherwise let Caml_obj.equal do its magic | ||
| | (Some(BigDecimal(bdA)), Some(BigDecimal(bdB))) => BigDecimal.equals(bdA, bdB) | ||
| | (a, b) => a == b |
There was a problem hiding this comment.
It might not work for array of BigDecimal
There was a problem hiding this comment.
If we handle them in a custom way, then we can use === instead of Caml_obj.equal, which should be a little bit faster and clener output
There was a problem hiding this comment.
If we handle them in a custom way, then we can use === instead of Caml_obj.equal, which should be a little bit faster and clener output
This comment is optional
| {{#each entities as | entity |}} | ||
| {{entity.name.uncapitalized}}: { | ||
| get: makeLoader(loadLayer.{{entity.name.uncapitalized}}, ~entityName={{entity.name.capitalized}}, ~entityIdsMap), | ||
| get: makeLoader(loadLayer.{{entity.name.uncapitalized}}, ~entityName={{entity.name.capitalized}}, ~entityIdsMap, ...), |
| {{#each entities as | entity |}} | ||
| loadLayer.{{entity.name.uncapitalized}}->executeLoadActionMap( | ||
| ~inMemTable=inMemoryStore.{{entity.name.uncapitalized}}, | ||
| ~batchLoadIds=Entities.batchRead(~entityMod=module(Entities.{{entity.name.capitalized}}))(DbFunctions.sql, _), | ||
| ~batchLoadIds=DbFunctionsEntities.batchRead(~entityMod=module(Entities.{{entity.name.capitalized}}))(DbFunctions.sql, _), | ||
| ~whereFnComposer=DbFunctionsEntities.makeWhereEq( | ||
| DbFunctions.sql, | ||
| ~entityMod=module(Entities.{{entity.name.capitalized}}), | ||
| ), | ||
| ), | ||
| {{/each}} | ||
| ]->Promise.all |
There was a problem hiding this comment.
A comment for future. If there's an external await in between of .load method calls, then hasLoadActions check won't be able to track it exit. It'll cause the .load method to stack as an unresolved pending promise.
| loadCallbacks: [loadCallback], | ||
| }, | ||
| ) | ||
| | Some({loadCallbacks}) => loadCallbacks->Js.Array2.push(loadCallback)->ignore |
There was a problem hiding this comment.
Just a random idea, but theoretically, it might be faster. But the number of allocated function contexts is a concern
| | Some({loadCallbacks}) => loadCallbacks->Js.Array2.push(loadCallback)->ignore | |
| | Some(lookup) => { | |
| lookup.callback = (v) => { | |
| lookup.callback(v) | |
| loadCallback(v) | |
| } | |
| } |
There was a problem hiding this comment.
Another fun idea, which will probably be even more performant is to create a pending promise and expose the resolve function:
let resolveRef = ref(%raw(`null`))
let resultPromise = Promise.make((resolve, _reject) => {
resolveRef := resolve
})
// Store both resultPromise and resolve in the LoadLayer
// Then when we add a new item to the LoadLayer we can do:
let _ = resultPromise->Promise.thenResolve(callback)
// And to actually resolve everything simply run the resolve function
resolve(result)There was a problem hiding this comment.
note: I don't have benchmarks and since it's not a bottleneck, you don't need to change anything
There was a problem hiding this comment.
Let's chat through some of these thoughts on a call! Definitely keen to squeeze more performance.
1917fca to
4e922e8
Compare
DZakh
left a comment
There was a problem hiding this comment.
I didn't read some places in much details, but in general I don't have any comments 👍
4e922e8 to
60afd3d
Compare
Implements "where equals" query for loaders on all indexed fields.
Flow:
Note this can only be done in a loader because... In the scenario where you add a new entity that exists only in memory. The index needs to exist on the in memory table before the add in order for it to appear on lookup in the index.
Deleting an entity will search through all indices on that entity and remove its id from any index it exists in.
The mock db in test helpers will currently prune all indexes of an entity and then add indexes for all fields of that entity every time an operation is called to prevent stale values existing in indices.