-
-
Notifications
You must be signed in to change notification settings - Fork 735
Allow multiple find/count operations on queries. Expose fromNetwork and isRunning #661
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #661 +/- ##
============================================
- Coverage 52.88% 52.56% -0.33%
+ Complexity 1676 1673 -3
============================================
Files 131 131
Lines 10150 10106 -44
Branches 1408 1405 -3
============================================
- Hits 5368 5312 -56
- Misses 4340 4353 +13
+ Partials 442 441 -1
Continue to review full report at Codecov.
|
Any thoughts about this? |
1edb3d4
to
83f1bd0
Compare
/* package */ ParseQuery<T> fromNetwork() { | ||
checkIfRunning(); | ||
|
||
public ParseQuery<T> fromNetwork() { |
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.
So, fromNetwork
is just the opposite of fromPin
?
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.
Yes! Before this being exposed, if you had a ParseQuery
and called query.fromPin()
or query.fromLocalDatastore()
there was no way to switch back to network from the same query object. This PR allows that and also allows calling find()
multiple times from the same object.
} | ||
} | ||
} | ||
|
||
/** | ||
* Cancels the current network request (if one is running). | ||
*/ | ||
//TODO (grantland): Deprecate and replace with CancellationTokens |
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.
Should we do what this comment suggests? Deprecate and replace with cancellation tokens?
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 don’t know what that means.. We should overload the signature of find, findInBackground, count & countInBackground to allow a CancellationToken
?
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 we would have it where each of those operations would return a cancellation token, which you could then use with .cancel(token)
which would cancel that specific call. But, I think that goes beyond the scope here and can be addressed in a different PR if desired. 👍
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 get your point, but find / count operations already have a return type, how would we pass back a CancellationToken
the moment one calls find?
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.
Now the cancellation is handled by the SDK itself. I think this suggestion means using the CancellationTokenSource
/CancellationToken
to transfer the cancellation handler to Bolt. But it is a big work, bunch of related files need to be modified. Another PR to do this job is preferred.
https://github.com/BoltsFramework/Bolts-Android#cancelling-tasks
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.
On top of that , if they wanted to deprecate query.cancel()
, they probably meant to have the developer get / pass a CancellationToken
and call source.cancel()
so the token is notified. See also the comment here.
The same comment is left in ParseFile
e.g. here. We might set up a PR that addresses this in both classes. But the only way I see this possible is overloading methods, like
CancellationTokenSource source = new CancellationTokenSource();
query.findInBackground(callback, /* nullable */ source.getToken());
// At any moment..
source.cancel();
It would be useful because ParseFile
and with this PR ParseQuery
allow multiple concurrent operations, so passing a token to each lets the developer cancel only one operation. If you think it’s needed I’m going to work on it (separately), with the plan
- overload methods to accept a token
- deprecate
cancel()
and have it fallback tocancelAll()
- create
cancelAll()
that cancels all currently running task
So the developer either passes a cancellation token to a single operation or uses cancelAll
if he doesn’t care.
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 should be implemented internally first, and keep the developer's original behavior. Replace the Task<Void> cancellationToken
in ParseQueryController
with CancellationToken cancellationToken
.
interface ParseQueryController {
<T extends ParseObject> Task<List<T>> findAsync(ParseQuery.State<T> state, ParseUser user,
CancellationToken cancellationToken);
<T extends ParseObject> Task<Integer> countAsync(ParseQuery.State<T> state, ParseUser user,
CancellationToken cancellationToken);
<T extends ParseObject> Task<T> getFirstAsync(ParseQuery.State<T> state, ParseUser user,
CancellationToken cancellationToken);
}
Then re-implement all the relevant files and pass cancellationToken to Bolt Task methods (ex. onSuccessTask).
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.
OK, I’ll do that just internally for queries and files then. 👍 going to open a separate PR though, do you think this can be merged?
83f1bd0
to
bc94bcc
Compare
I made this consistent with ParseFile so it will be easy if later we want to implement CancellationTokens. |
Does ParseQuery need a method to reset constraints (ex. |
That should clear all constraints (order, where etc.) just like |
Yeah, I just think about the concept of "query group". Developers can use a single |
This:
ParseQuery.fromNetwork()
& allow multiplefind()
/count()
#6