I want to create a revision/examination app for 20k+ students. I am going to take a test every day for all students (users app) of my app. and then store their records(scores) as total marks on the cloud Firestore. so my problem is I want to display students' rank order by their scores(while sorting their total marks). so if a student goes to the rank page to see the top students, the app will call 20k documents ordered by their total marks descending,
body: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('Users')
.doc('Students')
.collection('Regions')
.doc('regionName')
.collection('Districts')
.doc('DIstrictName')
.collection('Student_Phone')
.orderBy('Total_Marks', descending: true)
//time registered students
.orderBy('Created', descending: false) the right one
.snapshots(),
builder: (BuildContext context, snapshot) {
return ListView.builder(
itemCount: snapshot.data.docs.length,
itemBuilder: (context, index) {
return showUsers(
index: index,
snapshot: stuSnapShot.data.docs[index],
);
});
.......}
as well as I have to show 'my score page' for the student to show him his rank this will also want to retrieve the 20k documents to iterate through using this.
class showUsers extends StatefulWidget {
var snapshot;
final int index;
showUsers({@required this.snapshot, @required this.index});
@override
_showUsersState createState() => _showUsersState();
}
class _showUsersState extends State<showUsers> {
@override
Widget build(BuildContext context) {
var numNum = widget.snapshot.data()['PhoneNumber'].toString();
if (numNum == '+8977106429') {
return Container(
child: Text(
'you are :${widget.index} phone =$numNum',
style: TextStyle(
color: Colors.red, fontSize: 16, fontWeight: FontWeight.bold),
),
);
}
}
}
. and this will cost a lot of money to the firebase cloud Firestore pricing when 20k students read 20k documents per day 20,0000 X 20,000= 400,0000,0000 ==400m reads per day, which will cost= $720 per day which equals 30 X $720=$21,600. so is there another way to read these documents without that cost?