Michael Rutkowski
Michael Rutkowski

Reputation: 61

Does Firestore count "Re-Reads" as document reads?

I am trying to use Geofirestore to query results in a given radius from a center location. As far as I know, GeoFire can't limit the number of results queried. My solution to this problem is to increment my radius in steps until I get X amount of results. It seems by doing this, I will re-query results multiple times which could be costly. If I query 10 results but want 20. Would Firestore consider this as 30+ reads?

Upvotes: 1

Views: 207

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598916

The geoquery implementations I know of on top of Firestore all use geohashes for their implementation, which means they combine latitude and longitude into a single value, that can then be used to filter all documents within a certain geographical range. While it may technically be possible to limit the number of documents returned by adding a limit(...) to the query, the results will not be ordered by their distance to the center of the query. So you're likely to simply get results in one area of the queries range, instead of the closest documents.

Firestore charges you for all documents read from the server. Since it has a local cache, this may not be all the documents for your subsequent query, as the documents from the previous query may already be in the local cache.

That said: be aware that using geohashes for geoqueries leads to significant over-reading of documents. In my experimentation this can lead to reading between 3x and 10x more documents than are within the queried range. I'd highly recommend reading/watching up on geohashes and geoqueries on Firestore, for example by watching this talk I gave a while ago about the topic: https://www.youtube.com/watch?v=mx1mMdHBi5Q.

Upvotes: 1

Related Questions