Let's assume there is a blog and you would like to list the most liked or shared posts for today, the last 7 days and the last 30 days.
The solution for today is rather easy:
-mostSharedPostsForToday
-2018-10-08
-$postId
-numberOfShares
Then the query would observe mostSharedPostsForToday/2018-10-08
for today's most shared posts ordered by child numberOfShares
.
But how to structure the data for the most shared posts in the past n days?
One solution I can think of is to write a cloud function that populates the node mostSharedPostsForThePastNDays
on a daily basis. But it seems cumbersome to me. Isn't there a more efficient way?
Edit: As pointed out in the comments of the 1st answer pagination should be supported to save traffic.