fluttercommunity / firestore_helpers

Firestore Helpers - Firestore helper function to create dynamic and location based queries. Maintainer: @escamoteur
https://pub.dev/packages/firestore_helpers
MIT License
48 stars 19 forks source link

Issue with getDataFromQuery #3

Closed miduch closed 6 years ago

miduch commented 6 years ago

I am using getDataFromQuery as shown in example, applying query constraints and getting results back as expected. But when in FB console I manually update any item, then I get all items instead of only those which I got after applying constraints in first place.

Thanks

escamoteur commented 6 years ago

Sounds strange. What if you change the data from your App? Did you see any message in your debug output that you have to add a FireStore index?

miduch commented 6 years ago

I saw that message when running query, clicked on link and it created index. After that query returns correct/filtered results.

I can try to push some data from app side to see what happens

miduch commented 6 years ago

Similar to what I see

https://stackoverflow.com/questions/48489895/firestore-query-reads-all-the-documents-again-from-database-when-only-one-is-m

escamoteur commented 6 years ago

Wait, I'm not clear what you problem is. Is it that you get the whole collection updated when a single document changed or that the constraints are ignored in that case? The former is the default behavior.

miduch commented 6 years ago

“constraints are ignored in that case“.

Suppose I have 5 items and by applying constraints I get back item 2 only. After that I am listening to that stream. While listening I go to FB console and update item 4. In app stream gives me all 5 items this time.

If this is default behavior then is there a way to avoid this? And still have my query valid?

escamoteur commented 6 years ago

Wow, that is strange and different to the stack overflow question. I only pass the constraints down to Firebase so I don't have an idea right now what could be the problem. Could you try to access your collection without firestore_helpers and see if you get the same effect?

miduch commented 6 years ago

Tried to create new item from within app while it was showing filtered ones only (1 item only). This time it DID NOT push all items. Displayed items in app remained same as newly created item didn't match query constraints.
To test further i created another item which DID match with those constraints and this newly created item appeared in app as expected (2 item displayed total matching query constraints)

miduch commented 6 years ago

Now tried WITHOUT firestore_helpers and seems to work fine.

Stream snapshots = collectionReference.where('city', isEqualTo: 'Paris').snapshots();

at first i get only 1 item as expected. Then in FB console manually changed random items and it didn't effect app. Then changed in another item city to be Paris , this time app got notification and and i got 2 items matching Paris city.

looks like there is bug in firestore_helpers

miduch commented 6 years ago

some more info. It seem to ONLY happen when i apply LocationsConstraint , with !LocationsConstraint it works fine

escamoteur commented 6 years ago

@miduch I tried to reproduce your issue without success. Can you try the lastest version v2.0.6 with cloud_firestore v0.8.0 ?

Actually the change you made was like it was in v2.0.3 and I changed there. As Query is an ancestor of CollectionReference this should not make any difference.

miduch commented 6 years ago

sorry it took a while to try out again. Issue is still reproduced with v 2.0.6 / 0.8.0

escamoteur commented 6 years ago

But when you change that one line it works? Could you try v 2.0.3 that should be the same. And please explain again the steps you do when doing this. Also show me your code where you call get data and where you define your constraints.

escamoteur commented 6 years ago

@miduch any new on this?

miduch commented 6 years ago

one line change: nope that was my mistake, as i thought it was having this issue with all request but later i realised that it happens ONLY when i use

List getLocationsConstraint(String fieldName, Area area) {} for area i used hardcode lat/lon and tried with 10-500 km radius ` List locationConstraints = getLocationsConstraint('location', _area); repo.getEvents(queryConstraints: locationConstraints);

Stream< List< Event > > getEvents({List queryConstraints}) { Query query = buildQuery( collection: eventsCollection, constraints: queryConstraints); return getDataFromQuery( query: query, mapper: (documentSnapshot) { return Event.fromDocument(documentSnapshot); }); } ` Next list to stream, you will get items filtered with area correctly.

After this go to FB console and manually edit ANY item in collection (edit any field, doesn't need to be location). Stream in app will get all items from collection at this point

escamoteur commented 6 years ago

I tried and cannot reproduce it, sorry