2

We are developing an app that needs to show 50 'available' users inside a given distance range (users can be 'available' or 'not available'). On a Firebase cloud function, GeoFirestore is used to perform geoqueries to filter by distance, and the user 'availability' is checked client side (due to Firestore inequality signs usage limitations).

Now the problem is..

Does anyone know how to paginate the results at a query level? Pagination would be extremely useful to reduce number of reads on Firestore and consequently to contain costs. It is NOT mandatory results are sorted by distance, the goal is to find 50 'available' users inside the given range in a dataset of hundreds of thousands users.

  • Pagination isn't really a thing with geohashes. However, and I'm not sure if this is helpful at all, if your `availability` property is a `boolean`, you should be able to add to your query a `.where('availability', '==', true)`. You may need to create an index for that, but it should cut down on your reads. – MichaelSolati Feb 20 '21 at 07:22
  • @MichaelSolati Thanks Michael. The problem is that if there are 5000 ‘available’ users in the given distance range, each time the current user starts the app, 5000 reads are registered on Firestore. And this is true for thousands of users opening daily the app, more than once a day most of the time. Correct me if I’m wrong, but ‘Limit’ is applied client side by GeoFirestore. Is it right? Ps: 'availability' is determined by different parameters...One of which is excluding all users' ids the current user has already met (to simplify the explaination..) – Pier Venus-Comb Feb 22 '21 at 14:36
  • Limit is kinda applied client side. So hypothetically, a geoquery can be composed of 8 different queries, each of those queries has the limit applied to them. So if you set the limit to 10, then you'll likely return up to 80 docs. From there the client will sort them based on distance and then limit it to just 10. This is done because lets say if your geoquery requires 8 geohas queries in order to cover the area you want, hypothetically 7 of those 8 queries could have no results... So it needs to over collect results in order to give you that limit that you want. – MichaelSolati Feb 25 '21 at 17:56
  • @MichaelSolati Thanks for the more accurate explanation – Pier Venus-Comb Mar 08 '21 at 12:24

0 Answers0