imperiumlabs / GeoFirestore-Android

GeoFirestore for Android - Realtime location queries with Firestore
MIT License
123 stars 36 forks source link

GeoFire still retrieving documents from cache even though I've disabled it #35

Open jkrouz opened 5 years ago

jkrouz commented 5 years ago

My Firestore is still retrieving documents from cache even though I've explicitly told it not to.

At the moment GeoFirestore is the only code retrieving documents from cache. Examples from my GeoFire onDocumentEntered callback below:

override fun onEvent(documentSnapshot: DocumentSnapshot?, exception: FirebaseFirestoreException?) {
    Log.d(TAG, "$documentSnapshot")

See the logs below:

DocumentSnapshot{key=instances/mQhRbBHCiKEB, metadata=SnapshotMetadata{hasPendingWrites=true, isFromCache=true}

DocumentSnapshot{key=instances/d6MsxlZWfgk3, metadata=SnapshotMetadata{hasPendingWrites=false, isFromCache=true}, doc=Document{key=instances/d6MsxlZWfgk3}

Is there something in GeoFire's code that forces Cache reads?

PS: I've posted a Stack Overflow question regarding this issue here

Supercaly commented 5 years ago

Currently, there are no settings in GeoFirestore to prevent or force cache reads

jkrouz commented 5 years ago

Hi @Supercaly - i've asked a related Q on Stackoverflow: https://stackoverflow.com/questions/58677916/firestore-returning-deleted-documents-in-queries

The library is having inconsistencies with cache reads - specifically:

  1. Reading from cache even though persistence has been disabled

  2. Saying documents are from cache even though they are not

Is there any solution around this?

cbarrios commented 4 years ago

Hi @Supercaly. I'm giving a try to this library. I did notice that onDocumentEntered callback is still retrieving docs even thou they are removed when you requery. While the listener is active, however, onDocumentExited is only called. Common scenario of this issue is the following: you query a particular area then you requery another area with 0 docs then you delete yours docs of the old area then you requery the old area and both OnDocumentEntered and OnDocumentExited are fired with the old docs which they no longer exist in db but apparently they persist in cache. Please fixing this would be so much nicer. Thank you.

cbarrios commented 4 years ago

Hi @Supercaly - i've asked a related Q on Stackoverflow: https://stackoverflow.com/questions/58677916/firestore-returning-deleted-documents-in-queries

The library is having inconsistencies with cache reads - specifically:

  1. Reading from cache even though persistence has been disabled
  2. Saying documents are from cache even though they are not

Is there any solution around this? @jkrouz

This specific sequence will work for latest version of this library(v1.5.0). Give it a try. Put this on the onCreate() method or any other init method.

firestore = FirebaseFirestore.getInstance();
firestoreSettings = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(false).build();
firestore.setFirestoreSettings(firestoreSettings);
geoFirestore = new GeoFirestore(firestore.collection("name"));