-
Notifications
You must be signed in to change notification settings - Fork 67
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
Adds async option for find method - #19 #53
base: master
Are you sure you want to change the base?
Conversation
Ok I fixed this option if not specified from the schema. thoughts ? |
var relatedType = relationDef[relationType]; | ||
if (typeof relatedType !== 'string') { | ||
var relationOptions = relatedType.options; | ||
if (relationOptions && relationOptions.async && (async === undefined)) { |
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.
I think it would be better to just do !async
here instead of async === undefined
, so that it captures all truthy/falsy cases.
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.
Actually wait, I think maybe the best would be typeof idOrIds === 'undefined'
. You're trying to determine whether idOrIds
is undefined, right? We already know that async
is false at this point in the code.
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.
Also the reason it's better to do typeof foo === 'undefined'
rather than foo === undefined
is because technically people can re-assign the undefined
object in JavaScript
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.
Yep you're right ! Thanks for your review. I'm gonna improve that in the evening. Good to know you're ok with this feature anyway.
I don't think the I think this PR needs a bit of work to ensure that the correct behavior occurs for the four possible cases (async true/false for schema/query), but it's going in the right direction. Thanks! |
Hmmm not sure if I understand well your last comment ... I tried to modify the By default async equals false so indeed I defined it to true in the schema. Then if I don't find with the forced async option to false, I get res.books undefined as expected. I updated the check with typeof. |
Sorry, what I meant to say is that I was unsure we had enough tests, and that I didn't really understand what the It kinda looks like the |
The |
@@ -321,6 +321,8 @@ The following options based on the options for [PouchDB batch fetch](http://pouc | |||
* `limit`: Maximum number of documents to return. | |||
* `skip`: Number of docs to skip before returning (warning: poor performance on IndexedDB/LevelDB!). | |||
|
|||
Also it is possible to add an async option `{async: true|false}` in order to force to sideload or not dependent objects. Please refer to the [Async relationships](#async-relationships) chapter for more details. |
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.
^ It's not clear to me if this means that is overrides in both cases. I.e. if the default is true
and you set false
here, it overrides, is that right? And if the default is false
but you set true
here, then it also overrides? If that's the case, then the code should probably need to check for typeof relationOptions.async !== 'boolean'
as well as simple truthy/falsy, since it will be falsy in the case where it's not defined at all.
I'm starting to understand the general idea behind the code, but I think if we had a bit more tests for all edge cases (default is true/false, override is true/false, override is not specified, idOrIds is specified or not, idOrIds is |
Ok ! I'll back on this next week, sorry I had some stuffs to finish before ;) |
Just bumped into this problem, which slows things down quite significantly in some queries where you don't need all that data to be pulled in (easy to bypass by going back down to allDocs, but not very pretty). Has there been any progress on this? Happy to help move it forward if this PR is stalled and a contributor is needed! |
I've just implemented the proposal of @basco-johnkevin because I have the same need :)
Please let me know if it's fine for you.