-
Notifications
You must be signed in to change notification settings - Fork 442
Open
Description
[REQUIRED] Please fill in the following fields:
- Unity editor version: 2020.3.9f1
- Firebase Unity SDK version: 7.2.0
- Source you installed the SDK: Unity Package Manager with tgz
- Problematic Firebase Component: Firestore
- Other Firebase Components in use: Auth, Crashlytics, Remote Config
- Additional SDKs you are using:
- Platform you are using the Unity editor on: Windows
- Platform you are targeting: Android
- Scripting Runtime: IL2CPP
[REQUIRED] Please describe the question here:
I stumbled about the following information when looking into Firestore's cache behavior:
These things (set(), update(), or delete()) will happen eventually, if the app comes back online and the SDK is able to sync. But if the app process dies while offline and is relaunched online, those methods of tracking the completion of the operation will no longer work.
When I understand this correctly, data saved to the cache before the app dies/stops is not automatically updated to the Firestore backend when the app launches again.
Is this correct and when yes, what would be the best way to handle the "out of sync" data only present in the cache?
danielginovker
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-][Question] [/-][+][Question] "Out of sync" data in Firestore[/+]dconeybe commentedon Jun 28, 2021
Hi @Nyankoo. A quick Google search for that quote lead me to this article: https://medium.com/firebase-developers/firestore-clients-to-cache-or-not-to-cache-or-both-8f66a239c329. Is this where you copied that quote from?
Assuming it is, I believe you are asking if writes made while offline will eventually be sync'd to the backend when the app goes back online, even if interrupted by an app restart. If that is your question then the answer is "yes". Although the promise/task/callback initially attached to the write operation no longer exist after the app is restarted, the write is recorded in the local cache and will be sync'd with the backend once connectivity is restored.
Does this answer your question?
Nyankoo commentedon Jun 28, 2021
Hi @dconeybe, thank you for the quick answer!
Yep, that's where the quote is from! Sorry about that, I forgot to add the link to the article in my post.
When attaching a listener directly on the app's startup, is this sync then reflected in
querySnapshot.Metadata.HasPendingWrites
whenquerySnapshot.Metadata.IsFromCache
is true?dconeybe commentedon Jun 28, 2021
Yes.
HasPendingWrites
will change tofalse
once the write has been written to the backend.IsFromCache
may still betrue
if the document has not yet been read from the backend, which means there may be changes that occurred to the document by other apps/users that have not been downloaded into the local cache.Nyankoo commentedon Jun 28, 2021
@dconeybe Just to confirm:
HasPendingWrites
will change totrue
when the write is successfully send to the backend? Shouldn't it befalse
instead?dconeybe commentedon Jun 28, 2021
Oops, yes. Sorry. That was a typo (I've edited that comment to correct it). You are correct:
HasPendingWrites
will change tofalse
once the write has been successfully written to the backend.Note that you can also call
FirebaseFirestore.WaitForPendingWritesAsync()
to get aTask
that completes when all writes have completed.Nyankoo commentedon Jun 28, 2021
@dconeybe I'm experiencing a really weird issue when testing offline-syncing. Here is simplified code to see the call order:
This behavior is reproduceable on my end every time I add or remove
DisableNetworkAsync
, but our project is too big to create a sample project from it in the near future.Maybe I'm missing something here anyway, so it would be great when you could take a look.
dconeybe commentedon Jun 29, 2021
@Nyankoo This definitely does not sound like intended behavior.
A few questions:
FirebaseFirestore.LogLevel
toDebug
, reproduce, capture the logs, and post them?Thank you.
Nyankoo commentedon Jun 29, 2021
@dconeybe
FirebaseFirestore.LogLevel Debug
enabled here:firestore.txt
You can search for "Repetitions" to see our manual log outputs to see the value change.
dconeybe commentedon Jun 30, 2021
Hi @Nyankoo. I attempted to reproduce the behavior you're noting but did not have success. I observed the expected behavior.
Here the test script that I used. Each time I would uncomment exactly one of the "steps" and re-run the app in the Unity Editor.
Each time I observed the expected output, which looked like this:
I'm going to comb through your logs now and see if anything looks suspicious. Can you take a look at my code here to see if it accurately captures what you're trying to do?
18 remaining items