My app recently started facing this issue where it will save the write operations in the cache and will take hours or even days to sync with the server.

I am using MVVM architecture in my Android app which includes Koin for dependency injection and Kotlin as the programming language. Here's the class that creates the Firestore database instance and then performs the read/write operations.

object FirebaseRepository {
    private val db by lazy { Firebase.firestore }
    private val storage by lazy { FirebaseStorage.getInstance().reference }

    fun addLink(uid: String, params: Map<String, Any?>) = db.collection("$USERS_LINKS_PATH/$uid").add(params)
    fun updateLink(uid: String, docId: String, params: Map<String, Any?>) = db.collection("$USERS_LINKS_PATH/$uid").document(docId).set(params, SetOptions.merge())
}

Next, I call these methods from my ViewModel class as follows,

if (!link.documentId.isNullOrBlank()) { // Update existing link
    FirebaseRepository.updateLink(id, link.documentId, params)
} else { // Add new link
    FirebaseRepository.addLink(uid, params)
}

Now, when I perform this add or update operation, the changes are kept in the cache by the Client SDK and it takes hours to get in sync with the server.

I have checked with various networks and made sure none of them were restricted. I also tried different devices containing different Android OS versions. The problem is the same.

However, In the same database, my iOS app writes almost instantly on the server being on the same network. I also changed my code to an old branch when it was working perfectly fine. But now, even with that code, the data is not synced.

My Firestore and other Firebase services's versions are as follows

// Firebase
implementation 'com.google.firebase:firebase-firestore-ktx:24.9.1'
implementation 'com.google.firebase:firebase-storage-ktx:20.3.0'
implementation 'com.google.firebase:firebase-crashlytics-ktx:18.5.1'
implementation 'com.google.firebase:firebase-analytics-ktx:21.5.0'
implementation 'com.google.firebase:firebase-messaging-ktx:23.3.1'
implementation 'com.google.firebase:firebase-dynamic-links-ktx:21.2.0'
implementation 'com.google.firebase:firebase-perf-ktx:20.5.0'

I want to understand why is this not working properly on Android since last week. it used to work perfectly and I didn't make any such changes that it should behave like this.

PS: I cross-checked multiple times on different networks (including Wifi and mobile networks) on various devices (including Samsung, Vivo, OnePlus, MI, Google).

0

There are 0 answers