Skip to content

Commit 33fdaa0

Browse files
committed
comment + remove action from outstanding get
1 parent 33308dd commit 33fdaa0

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

firebase-database/src/main/java/com/google/firebase/database/connection/PersistentConnectionImpl.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,15 @@ public String toString() {
115115
private static class OutstandingGet {
116116
private final Map<String, Object> request;
117117
private final ConnectionRequestCallback onComplete;
118-
private final String action;
119118
private boolean sent;
120119

121120
private OutstandingGet(
122121
String action, Map<String, Object> request, ConnectionRequestCallback onComplete) {
123-
this.action = action;
124122
this.request = request;
125123
this.onComplete = onComplete;
126124
this.sent = false;
127125
}
128126

129-
private String getAction() {
130-
return action;
131-
}
132-
133127
private ConnectionRequestCallback getOnComplete() {
134128
return onComplete;
135129
}
@@ -1172,7 +1166,7 @@ private void sendGet(final Long readId) {
11721166
}
11731167
}
11741168
sendAction(
1175-
get.getAction(),
1169+
REQUEST_ACTION_GET,
11761170
get.getRequest(),
11771171
new ConnectionRequestCallback() {
11781172
@Override

firebase-database/src/main/java/com/google/firebase/database/core/Repo.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,29 @@ public void onRequestResult(String optErrorCode, String optErrorMessage) {
467467
this.rerunTransactions(affectedPath);
468468
}
469469

470+
/**
471+
* The purpose of `getValue` is to return the latest known value satisfying `query`.
472+
*
473+
* <p>If the client is connected, this method will send a request to the server. If the client is
474+
* not connected, then either:
475+
*
476+
* <p>1. The client was once connected, but not anymore. 2. The client has never connected, this
477+
* is the first operation this repo is handling.
478+
*
479+
* <p>In case (1), it's possible that the client still has an active listener, with cached data.
480+
* Since this is the latest known value satisfying the query, that's what getValue will return. If
481+
* there is no cached data, `getValue` surfaces an "offline" error.
482+
*
483+
* <p>In case (2), `getValue` will trigger a time-limited connection attempt. If the client is
484+
* unable to connect to the server, the will surface an "offline" error because there cannot be
485+
* any cached data. On the other hand, if the client is able to connect, `getValue` will return
486+
* the server's value for the query, if one exists.
487+
*
488+
* <p>`getValue` updates the client's persistence cache whenever it's able to retrieve a new
489+
* server value. It does this by installing a short-lived tracked query.
490+
*
491+
* @param query - The query to surface a value for.
492+
*/
470493
public Task<DataSnapshot> getValue(Query query) {
471494
TaskCompletionSource<DataSnapshot> source = new TaskCompletionSource<>();
472495
this.scheduleNow(

0 commit comments

Comments
 (0)