How to restict timely manner update document in Firestore database with poor network connections

不想你离开。 提交于 2021-01-05 07:00:06

问题


I've create android application in which we used Firestore database.
I want to update firebase document within time.
Firestore is quick to post on server but when there is any connection issue then it taking time to save on Firestore
My task is if User tried to update withing few seconds eg 20 seconds if user can't post that data on server withing 20 seconds then later on that update should not be post on server

If user is online and have good connection then there is no problem but if there is poor connection then it will create problem to me.
There was feasibility in realtime database but can't see in firestore

onDisconnectRef.cancel

I don't know how to manage this cancelation state but I've tried this code. It returning error that you can't do operation on running Firebase Instance Please suggest me what I need to do.

val hashMap = HashMap<String, Any>()
                        hashMap["status"] = "ACCEPTED"
                        hashMap["time"] = time
                        app().firestoreDB
                            .collection("doc")
                            .document("id")
                            .update(hashMap)
                            .addOnSuccessListener {
                                isStoredOnServer = true
                                // my action 
                            }

            object : CountDownTimer(20000, 1000) {
                    override fun onTick(millisUntilFinished: Long) {
                        if(isStoredOnServer){
                            this.cancel()
                        }
                    }
                    override fun onFinish() {
                        if(!isStoredOnServer) {
                            FirebaseFirestore.getInstance().clearPersistence()
                                .addOnFailureListener { e -> Log.d("Firestore", "Error persistence writing document $e") }
                                .addOnSuccessListener { Log.d("Could enable persistence:") }

                        }
                    }
                }.start()

来源:https://stackoverflow.com/questions/63700993/how-to-restict-timely-manner-update-document-in-firestore-database-with-poor-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!