Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9 Snapshot Listeners for 1 query? #161

Open
0radek opened this issue Jun 30, 2021 · 2 comments
Open

9 Snapshot Listeners for 1 query? #161

0radek opened this issue Jun 30, 2021 · 2 comments

Comments

@0radek
Copy link

0radek commented Jun 30, 2021

I'm using the .within() method and I notice that 9 snapshot listeners are created because of the surrounding geohashes.

image

Here's my code for what I'm doing - is this problematic at all? How to close the 9 listeners?

class SpacesStreamResults extends HookWidget {
  Stream<List<DocumentSnapshot<Map<String, dynamic>>>>? spacesStream;

  @override
  Widget build(BuildContext context) {
    final _spacesProvider = useProvider(spacesProvider);
    final _categoriesProvider = useProvider(categoriesProvider);

    useEffect(() {
      final queryRef = _spacesProvider.selectedCategories.isEmpty
          ? FirebaseFirestore.instance.collection('spaces').where(
                'open',
                isEqualTo: true,
              )
          : FirebaseFirestore.instance
              .collection('spaces')
              .where(
                'open',
                isEqualTo: true,
              )
              .where(
                'categories',
                arrayContainsAny: _spacesProvider.selectedCategories
                    .map((category) => "${category.id}")
                    .toList(),
              );

      this.spacesStream = geo
          .collection(
            collectionRef: queryRef,
          )
          .within(
              center: GeoFirePoint(36, -120),
              radius: 30,
              field: 'position');

      return () {
        this.spacesStream = null;
      };
    }, [_spacesProvider.selectedCategories]);

    return StreamBuilder<List<DocumentSnapshot<Map<String, dynamic>>>>(
      key: Key('spaces-streamBuilder'),
      stream: spacesStream,
      // initialData: [],
      builder: (BuildContext context,
          AsyncSnapshot<List<DocumentSnapshot<Map<String, dynamic>>>>
              spacesSnapshot) {
 
              // .................
              }
        ));
    }
}
@Hu1buerger
Copy link

Dosnt the GeoFireCollectionRef have a dispose() method?

@awaik awaik pinned this issue Jan 13, 2022
@cedvdb
Copy link

cedvdb commented Jan 20, 2022

don't quote me on this but I believe this is expected because it has to query multiple geohash squares. I don't know if 9 is exact but there is going to be more than 1 query.

That's one reason why we need Firestore itself to support Geoqueries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants