簡體   English   中英

FirebaseFirestore多個進程

[英]FirebaseFirestore multiple processes

我有一個帶有Firestore的應用程序。 我有很多存儲庫。 他們在Firestore工作。 當我同時調用2方法時,我得到了一個錯誤。

class CommentRepository : CommentRepositoryInterface {

    val firebaseFirestore = FirebaseFirestore.getInstance()


    companion object {
        const val COLLECTION_NAME = "post_comments"
        const val COMMENT_POST_ID_KEY = "postid"
    }

    override fun getPostCommentsById(postId: String): Observable<CommentModel> {

        return Observable.create { subscriber ->

            firebaseFirestore.collection(COLLECTION_NAME)
                    .whereEqualTo(COMMENT_POST_ID_KEY, postId)
                    .get()
                    .addOnCompleteListener { task ->

                        if (task.isSuccessful) {
                            for (document in task.result) {
                                if (document.exists()) {
                                    val documentModel = document.toObject(CommentModel::class.java)
                                    subscriber.onNext(documentModel)
                                }
                            }
                            subscriber.onComplete()
                        } else {
                            subscriber.onError(task.exception!!) // TODO
                        }
                    }
        }
    }
}

另一個幾乎與此相同,但是另一個正在使用另一個集合。 因此,當我調用這些函數時,出現了下一個錯誤:

Internal error in Firestore (0.6.6-dev).
Caused by: java.lang.RuntimeException: Failed to gain exclusive lock to the Firestore client's offline persistence. This generally means you are using Firestore from multiple processes in your app. Keep in mind that multi-process Android apps execute the code in your Application class in all processes, so you may need to avoid initializing Firestore in your Application class. If you are intentionally using Firestore from multiple processes, you can only enable offline persistence (i.e. call setPersistenceEnabled(true)) in one of them.

在MyApplication類中,我嘗試設置Fireton設置的Singleton。

val settings = FirebaseFirestoreSettings.Builder()
                .setPersistenceEnabled(true)
                .build()
        FirebaseFirestore.getInstance().firestoreSettings = settings

我在Firestore的文檔中找到了它:

對於Android和iOS,默認情況下啟用離線持久性。

有人有解決這個問題的想法嗎?

我已經清除了應用程序的緩存並解決了問題。

做到這一點或只是從手機中刪除! :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM