f-miyu / Plugin.CloudFirestore

MIT License
121 stars 44 forks source link

Access to documentRef "source" in GetDocument() #45

Closed barrysohl closed 4 years ago

barrysohl commented 4 years ago

The Firestore API allows you to specify a "source" when querying for a document:

documentRef.get({ source: 'server' }) // or 'cache'

We badly need access this to try to address performance issues we're having with offline access. Is that option available, and I'm just not finding it? Or if not, can it be added?

vincooys commented 4 years ago

The Firestore API allows you to specify a "source" when querying for a document:

documentRef.get({ source: 'server' }) // or 'cache'

We badly need access this to try to address performance issues we're having with offline access. Is that option available, and I'm just not finding it? Or if not, can it be added?

Hi Barry,

You can set the source to server or cache by specifying the Source.Cache when getting documents: .GetDocumentsAsync(Source.Cache)

Example:

await _firestore.GetCollection(Category.CollectionPath) .OrderBy("order", false) .GetDocumentsAsync(Source.Cache) .ConfigureAwait(false);

barrysohl commented 4 years ago

That fixed it!!! If I force 'source' to Cache when offline, our launch queries that took minutes are now sub-second. Even faster than when connected. Thanks!

vincooys commented 4 years ago

Great news! Glad you got your issue worked out