Skip to content

Commit

Permalink
Fixes firebase#134 and firebase#28. Using keyRef.updateChildren inste…
Browse files Browse the repository at this point in the history
…ad 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.
  • Loading branch information
joergwiesmann committed Sep 1, 2018
1 parent c46ff33 commit 0dc3835
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions common/src/main/java/com/firebase/geofire/GeoFire.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@

package com.firebase.geofire;

import static com.firebase.geofire.util.GeoUtils.capRadius;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import com.firebase.geofire.core.GeoHash;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.database.GenericTypeIndicator;
import java.lang.Throwable;
import java.util.*;
import java.util.logging.Logger;

import static com.firebase.geofire.util.GeoUtils.capRadius;
import com.google.firebase.database.ValueEventListener;

/**
* A GeoFire instance is used to store geo location data in Firebase.
Expand Down Expand Up @@ -172,14 +175,14 @@ public void setLocation(final String key, final GeoLocation location, final Comp
updates.put("g", geoHash.getGeoHashString());
updates.put("l", Arrays.asList(location.latitude, location.longitude));
if (completionListener != null) {
keyRef.setValue(updates, geoHash.getGeoHashString(), new DatabaseReference.CompletionListener() {
keyRef.updateChildren(updates, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
completionListener.onComplete(key, databaseError);
}
});
} else {
keyRef.setValue(updates, geoHash.getGeoHashString());
keyRef.updateChildrenAsync(updates);
}
}

Expand Down Expand Up @@ -212,7 +215,7 @@ public void onComplete(DatabaseError databaseError, DatabaseReference databaseRe
}
});
} else {
keyRef.setValue(null);
keyRef.setValueAsync(null);
}
}

Expand Down

0 comments on commit 0dc3835

Please sign in to comment.