Skip to content

Commit 0dc3835

Browse files
committed
Fixes firebase#134 and firebase#28. Using keyRef.updateChildren instead of keyRef.setValue also fixes a huge amount of unnecessary 'onDataExited(DataSnapshot dataSnapshot)' events which has not been reported yet. keyRef.updateChildren understands if the data needs to be inserted or updated. No need to use setValue here. Since priorities are not relevant anymore (https://stackoverflow.com/questions/31577915/what-does-priority-mean-in-firebase) i decided to not consider them anymore.
1 parent c46ff33 commit 0dc3835

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

common/src/main/java/com/firebase/geofire/GeoFire.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@
2828

2929
package com.firebase.geofire;
3030

31+
import static com.firebase.geofire.util.GeoUtils.capRadius;
32+
33+
import java.util.Arrays;
34+
import java.util.HashMap;
35+
import java.util.List;
36+
import java.util.Map;
37+
import java.util.logging.Logger;
38+
3139
import com.firebase.geofire.core.GeoHash;
3240
import com.google.firebase.database.DataSnapshot;
3341
import com.google.firebase.database.DatabaseError;
3442
import com.google.firebase.database.DatabaseReference;
35-
import com.google.firebase.database.ValueEventListener;
3643
import com.google.firebase.database.GenericTypeIndicator;
37-
import java.lang.Throwable;
38-
import java.util.*;
39-
import java.util.logging.Logger;
40-
41-
import static com.firebase.geofire.util.GeoUtils.capRadius;
44+
import com.google.firebase.database.ValueEventListener;
4245

4346
/**
4447
* A GeoFire instance is used to store geo location data in Firebase.
@@ -172,14 +175,14 @@ public void setLocation(final String key, final GeoLocation location, final Comp
172175
updates.put("g", geoHash.getGeoHashString());
173176
updates.put("l", Arrays.asList(location.latitude, location.longitude));
174177
if (completionListener != null) {
175-
keyRef.setValue(updates, geoHash.getGeoHashString(), new DatabaseReference.CompletionListener() {
178+
keyRef.updateChildren(updates, new DatabaseReference.CompletionListener() {
176179
@Override
177180
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
178181
completionListener.onComplete(key, databaseError);
179182
}
180183
});
181184
} else {
182-
keyRef.setValue(updates, geoHash.getGeoHashString());
185+
keyRef.updateChildrenAsync(updates);
183186
}
184187
}
185188

@@ -212,7 +215,7 @@ public void onComplete(DatabaseError databaseError, DatabaseReference databaseRe
212215
}
213216
});
214217
} else {
215-
keyRef.setValue(null);
218+
keyRef.setValueAsync(null);
216219
}
217220
}
218221

0 commit comments

Comments
 (0)