Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore: setting includeMetadataChanges = true does not result in receiving isFromCache = false after first run. #12869

Closed
TarekkMA opened this issue Apr 30, 2024 · 12 comments
Assignees

Comments

@TarekkMA
Copy link

Description

When querying documents using the options:

  • source set to FIRListenSourceDefault
  • includeMetadataChanges set to true\

The expected behavior is to receive two results. The first result should have isFromCache marked as YES, and the second should have isFromCache marked as NO. However, the actual behavior observed is that only one result is returned with isFromCache marked as NO.

Reference:

Reproducing the issue

  1. Set up a document query with source as FIRListenSourceDefault.
  2. Enable includeMetadataChanges.
  3. Observe the results.

Firebase SDK Version

10.24.0

Xcode Version

15.3

Installation Method

CocoaPods

Firebase Product(s)

Firestore

Targeted Platforms

iOS

Relevant Log Output

No response

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
Replace this line with the contents of your Package.resolved.

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!
@milaGGL
Copy link
Contributor

milaGGL commented Apr 30, 2024

Hi @TarekkMA, thank you for reporting this issue. includeMetadataChanges is working as expected in my local test environment. Would it be possible to provide a minimal reproduction app?

@ramsayamarin
Copy link

@milaGGL It works as expected when listening to a query the first time, but if you recreate the query or restart the app on the same exact data, it will not work as expected; it will return the cached data and never isFromCache == false until the data is updated again or the app storage cleared. This issue only happened after I updated to the latest version.

@milaGGL
Copy link
Contributor

milaGGL commented May 1, 2024

I have tested the below:

  1. create a snapshot listener -> receives 2 snapshots where isFromCache=true, and then isFromCache=false
  2. attach a second snapshot listener -> receives only 1 snapshot where isFromCache=false as expected.

Test 2:

  1. create a snapshot listener -> receives 2 snapshots where isFromCache=true, and then isFromCache=false
  2. remove the snapshot listener
  3. re-create a snapshot listener -> receives 2 snapshots where isFromCache=true, and then isFromCache=false

Both of them are working as expected in the SDK tests. Could you please provide a repro app?

@ramsayamarin
Copy link

ramsayamarin commented May 1, 2024

@milaGGL Are you using the latest version of cloud firestore (4.17.2) on a iOS device? The query has to be on the same exact data @TarekkMA seems to have successfully recreated the bug, I hope he can post it here. Otherwise I can try recreating it in a new project tomorrow.

@milaGGL
Copy link
Contributor

milaGGL commented May 1, 2024

I am testing it on firebase-ios-sdk v10.25.0 with iOS simulator.

@ramsayamarin
Copy link

ramsayamarin commented May 1, 2024

@milaGGL I have never ran my projects on the iOS simulator therefore this might be the issue. As for the SDK version you are using, I do not know which iOS SDK version cloud_firestore (4.17.2) internally uses so this might be another cause why the error is not reproducing on your side. Can you please try it on an iOS device with a Flutter project with cloud_firestore (4.17.2)?

@milaGGL
Copy link
Contributor

milaGGL commented May 1, 2024

The most recent change to snapshot listener is introduced in ios sdk v10.23.0, which maps to cloud_firestore 4.17.0.

Could you please provide a repro app on native iOS, not flutter, to narrow down the bug into the firebase-ios-sdk?

@TarekkMA
Copy link
Author

TarekkMA commented May 2, 2024

@milaGGL Sorry for the late reply, here's a reproduction repo. https://github.com/TarekkMA/firebase-ios-reproduction/tree/ff/12722.

You can see I get only one log statment with:

snapshot: isFromCache: 1

cc: @ramsayamarin

@milaGGL
Copy link
Contributor

milaGGL commented May 2, 2024

@TarekkMA, i am trying to reproduce the error on xcode. Meanwhile, could you please update the ViewController.m file line 38 to use the optionsWithSourceAndMetadata instead of options and try again? Currently it is not listening to metadata changes.

@milaGGL
Copy link
Contributor

milaGGL commented May 2, 2024

Test1

  1. create a snapshot listener -> receives 2 snapshots where isFromCache=true, and then isFromCache=false
  2. attach a second snapshot listener -> receives only 1 snapshot where isFromCache=false as expected.

Test 2:

  1. create a snapshot listener -> receives 2 snapshots where isFromCache=true, and then isFromCache=false
  2. remove the snapshot listener
  3. re-create a snapshot listener -> receives 2 snapshots where isFromCache=true, and then isFromCache=false

I tried the test1( creating a second snapshot listener) with the debug app, and it is working as expected.

Could you please add one more button to remove the snapshot listener, so that we can try the test2, re-create a listener? I tried to add the button, but iOS app is not my strong suit.

@TarekkMA
Copy link
Author

TarekkMA commented May 2, 2024

@milaGGL, thank you! It was an issue on our part. The problem was that we were not using optionsWithSourceAndMetadata; instead, we used options.

Now I'm getting 2 results, which solves our issue:

snapshot: isFromCache: 1
snapshot: isFromCache: 0

@milaGGL
Copy link
Contributor

milaGGL commented May 2, 2024

Nice! 🎉

Closing the ticket as the problem is solved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants