Currently my database looks like this:
Creating a Leaderboard has been fairly simple and straightforward so far:
I declare my stream in initState:
@override
void initState() {
futureAd = fetchAd();
_mainScoreStream = FirebaseFirestore.instance
.collection('users')
.orderBy('current_score', descending: true)
.where('current_score', isGreaterThan: 0)
.limit(25)
.snapshots();
super.initState();
}
Then use it in a ListView.builder:
Expanded(
child: ListView.builder(
physics: const BouncingScrollPhysics(),
itemBuilder: (context, index) {
DocumentSnapshot data = snapshot.data!.docs[index];
return LeaderboardCard(
currentScore: data['current_score'].toString(),
name: data['name'],
index: index,
isCurrentUser: data.id == user!.uid,
);
},
itemCount: snapshot.data!.docs.length,
),
),
But this makes it so that each users puts on an extra 25 reads when loading the Leaderboard
How can I create a Firebase Function that grabs the name
+ current_score
and puts that in a separate leaderboard document that a user can fetch instead so the reads can be cut to 1 instead of 25, or is there any other way to cut down reads while creating a leaderboard ?