Query collection with none, one, or multiple filters: How to best implement?

Database & APIs

I'm figuring out the best approach for a query / queries for a user search in the following scenario with Firebase:

  • Our app will have Users that will belong to one Group each; they will also belong to one Subgroup within that Group.

  • Since this may be performance-relevant: We expect between 250 and 2,500 Users in one Group as the most typical case. During a certain timeframe, these Groups change multiple times per day (i.e. Users being added, Users updating their profiles etc.), which means local caching may not make sense for longer periods.

  • In each Group there will be up to 25 Subgroups, each with perhaps up to 250 Users. Subgroups are not evenly large.

  • Users should only be able to find (and interact with) other Users in the same Group. I assume this would be doable by making them a subcollection of Groups.

  • For now, Subgroup affiliation can be handled by simply making it a string in the User document. If it makes things easier for querying, we can also have Subgroups as their own collection.

  • On the page for finding other Users, we would initially show all Users in the same Group. This list should have filters that should also be combined:

    1. Show only other Users where a specific string attribute has the same value as the authUser

    2. Show only other Users in the same Subgroup as the authUser

    3. (not crucial but would be nice) Show only other Users where one or more entries in a list of strings (think: custom tags) are equal to entries in a list of strings of the authUser.

What have you tried so far?

Based on tutorials I've seen with one filter it was suggested to have two ListViews (unfiltered and filtered); but I guess with that approach, with two filters, we would already need four ListViews (unfiltered; filter 1 on / filter 2 off; filter 1 off / filter 2 on; filter 1 & 2 on). And eight if we were to implement filter 3.

I'm sure there are other ways to handle it. What would be a best-practice approach to our requirements?

Did you check FlutterFlow's Documentation for this topic?
Yes
3
10 replies