f-miyu / Plugin.CloudFirestore

MIT License
121 stars 44 forks source link

Failed to get document because the client is offline. #96

Closed angelru closed 1 year ago

angelru commented 2 years ago

Hi, from time to time I get this random error. Anyone else have happened? I have to say, that other parts of the application works.

        public static async Task<bool> CheckIfFollowingAsync(string userId)
        {
            var document = await CrossCloudFirestore.Current.Instance
                                                    .Collection(Settings.FollowingCollection)
                                                    .Document(MyUserId())
                                                    .Collection(Settings.UserFollowingCollection)
                                                    .Document(userId)
                                                    .GetAsync();

            return document.Exists;
        }

This is the method that sometimes gives that exception

vhugogarcia commented 2 years ago

Instead of using nested queries. Try to get the document async by path (string).

So, first create the path variable set it as it should be for example: $"{Settings.FollowingCollection}/{MyUserId()}/.....

angelru commented 2 years ago

@vhugogarcia

 var document = await CrossCloudFirestore.Current.Instance
                            .Document($"{Settings.FollowingCollection}/{MyUserId()}/{Settings.UserFollowingCollection}/{userId}")
                            .GetAsync();

Does this really make a difference? I do not understand.

angelru commented 2 years ago

This usually happens when the application goes to OnSleep and then OnResume or it has not been opened for a long time. I think Firestore thinks there is no connection but there is. I don't know how to fix this. What I don't understand is why it looks at the cache when there is an internet connection.

When resuming the application should we call EnableNetworkAsync? Wait a few seconds for Firestore to connect?

@f-miyu know something about it? Does it have to do with the android SDK which is out of date?

https://github.com/firebase/firebase-android-sdk/blob/1c84b8eecb602b1c8a44a91e8671a92ee083cecc/firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentReference.java#L332