firebase transactions after restart with persistence enabled - firebase

I'm getting the following message from firebase:
runTransactionBlock: usage detected while persistence is enabled. Please be aware that transactions will not be persisted across app restarts.
So what exactly happens after the app restarts? Do the updates in my local database get overwritten due to a sync event from the main database? Something else?

Transactions are not persisted to disk. So when you app is restarted, none of your transactions will be sent to the server.
After regaining connectivity, your local cache will contain the data from the server.

Related

Does the firestore bundle facility require persistent offline cache in the client to be enabled

To use a firestore bundle, does the client need to have persistence enabled for the offline cache. If persistence is enabled, does it mean that the offline cache and the bundle are retained when the app or browser is closed and don't have to be re-downloaded when the app or browser window starts up again.
According to the firebase website, for the web, offline persistence is supported only by chrome, safari and firefox. Is this information up to date - is it possible that Edge, Opera and Brave browsers support persistent cache.
For the web, if cache persistence isn't available, is it possible to cache the firestore bundle locally some other way?
If the app requests to ead a document from the local cache and it's not there, will the document be read from the cloud if the device is online?
When you enable disk persistence, your app writes the data locally to the device so your app can maintain state while offline, even if the user or operating system restarts the app.
By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache. Listener callbacks will continue to fire for local updates.
Check the section here for more information on Handling Transactions Offline
Even with persistence enabled, transactions are not persisted across app restarts. So you cannot rely on transactions done offline being committed to your Firebase Realtime Database. To provide the best user experience, your app should show that a transaction has not been saved into your Firebase Realtime Database yet, or make sure your app remembers them manually and executes them again after an app restart.
As per the official documentation ,Offline persistence is supported only in Android, Apple, and web apps.For the web version, offline persistence is supported only by the Chrome, Safari, and Firefox web browsers
For the web, offline persistence is disabled by default. To enable persistence, call the enablePersistence method.
While network access is disabled, all snapshot listeners and document requests retrieve results from the cache. Write operations are queued until network access is re-enabled.
Also , check the following for similar implementations examples:
Firebase Offline persistence Upfront Caching
Firebase Offline possibilities
What happens when an offline device goes online

Flutter Firestore Offline Database

I have a clarifying question about Cloud Firestore and Flutter:
I am making an app that users can create log entries of sort, which will be saved on Firebase. But they might make up to 30 entries offline, before they have internet connection again.
And I know that Firestore has an offline feature, with which any created documents can be viewed offline because it is saved in the order of logging, and then synced with the database when internet connection is gained. But it is absolutely crucial that these logs cannot be lost in my app before having a chance of uploading it. Is there a way to ensure that my app will not lose this data before connecting to Firebase again, or should I create a Sembast database on the device, and save a copy of everything, and then check that once in a while against the database?
Does Firestore have offline contingency for if the phone's battery dies before it could sync with Firestore?
Or is there another solution I am unaware of?
For Android and iOS, offline persistence is enabled by default.
You don't have to do anything in your code.
Note there is a default cache size of 100 MB. This can be changed though, eg
let settings = Firestore.firestore().settings
settings.cacheSizeBytes = FirestoreCacheSizeUnlimited
Firestore.firestore().settings = settings
Does Firestore have offline contingency for if the phone's battery dies before it could sync with Firestore?
When Firestore's offline persistence is enabled, it stores data that your app has recently read, as well as any pending writes, to a database on the local device or browser. This disk based cache will survive restarts of the app/reloads of the page.
For new version of use below code -
FirebaseFirestore.instance.settings =
Settings(cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED);

Firebase Firestore not showing documents created by my flutter application

I was able to configure the Firestore database in Firebase with my flutter app and also create and read documents from my collection but when I go to Firestore console I don't see the created data, also when I creat data manually I am unable to see it in my application.
I am using the test mode which means any user can read or write.
I hope someone can help me with this puzzle.
Thanks!!!
It sounds like the device/emulator that you are running on is not connected to the internet, or at least not to the Firestore servers. In that case, the client writes all local changes into a local database, waiting to send them to the server when it gets a connection. So the local app will work, but won't be able to synchronize its local cache with the database servers.
You might want to check the connection on your device, and any proxies that might exist between your app and the Firestore servers.

What happen when closing Ionic Firestore app with offline persistance?

If I have Ionic 4 app that uses the firebase JS SDK (AngurlarFire5) with firestore's offline persistence enabled, what would happen if there are pending requests and the app get closed either by sending it to background or completely closing it? Would it sync when re-opening the app or the pending requests/data will be lost?
The way offline persistence works on all platforms is like this. When data is written, the write is committed to local storage before it's synchronized to the server. Eventually, when the app is running and it's able to connecto to Firestore again, the writes will be synchronized. Killing the app doesn't change this behavior. It just delays the sync until the app is launched again and is able to connect.

Is Firedatabase.SetPersistent (true) minimiza downloading data?

Using
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
Is this guarantee to download the data only one time across the App life/App restarts even if the user has good connection?
N.B: The official docs isn't clear ( at least for me) at this point.
By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache. Listener callbacks will continue to fire for local updates.
The sole goal of enabling persistence is to ensure that the app continues to work, even when the user starts it when they don't have a connection to the Firebase servers.
The client does send tree of hash values of its restored local state to the server when it connects, which the server then uses to only send the modified segments back. But there is no guarantee on how much data this sends or saves.
If you want to learn more about what Firebase actually does under the hood, I highly recommend enabling debug logging and studying its output on logcat.
For more on the topic, see these questions on Firebase's synchronization strategy.

Resources