简体   繁体   中英

How do I get only followed users with flutter firebase

The method below worked, but it seems to cause problems when there are 1 million followers, will my application crash?, i have no other idea.

the function i use:

  @override
  void initState() {
    super.initState();
    getdata();
    getComments();
  }

  List<String> pointList = <String>[];

getdata() async{
  await FirebaseFirestore.instance.collection("users").doc(widget.uid).get().then((value){
setState(() {
      // first add the data to the Offset object
      List.from(value.get("following")).forEach((element){
          //then add the data to the List<Offset>, now we have a type Offset
          pointList.add(element);
      });
      print(pointList[0]);
      });
   });
  }

Just read documentation and capabilities of firestore then ask questions. One document can have only 20k fields, so you cannot have a list with 1mil values. Create a sub collection attached to user document with many documents and each document will contain around 500-2000 records in list about followers. Or consider leaving that approach and just count how many people are following. For what, your Influencer account need to know everything about his followers? If you have no other idea to engineer your applications, just forget about programming career. No one will tell you how to do something every time. For them, faster will be to do it by them self.

Another approach, you can create only one document about followers and if he reaches about 500-2000 records with information about followers or unfollowers you can save that data to a file in firebase storage. This way you can have document with more than 1MB and 20k fields.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM