I'm trying to make a database that has posts posted by a user and only persons subscribed to this person can see the post . the problem here is that I add an event listener on parent node on hope that it returns child nodes that only apply to the read rule written inside the children , I do know about the "Rules are not filters" section in the documentation of fire-base and I can't reach a good time/memory efficient design where I only retrieve posts that apply to my rules. That's my database
{
"Users" : { // ids of users using the app
"6Ya6nxqRy1fKt4BUOOh1brCJzvi2" : true,
"Nxmo8Wlhlcg4GDvh7ZIAnmBbpS82" : true,
},
"followers" : {
"6Ya6nxqRy1fKt4BUOOh1brCJzvi2" : { //followers to the user with this id
"Nxmo8Wlhlcg4GDvh7ZIAnmBbpS82" : false,
"n9jTaFVPDNh6bJSSZZCT20UFA972" : true
},
"Nxmo8Wlhlcg4GDvh7ZIAnmBbpS82" : {
"6Ya6nxqRy1fKt4BUOOh1brCJzvi2" : true,
"n9jTaFVPDNh6bJSSZZCT20UFA972" : true
}
},
"posts" : {
"-M3YxODIv6frqFyGM4Nm" : { //post with a random generated Id
"img" : "cd4aaff5-cab9-44d6-b7d9-7587ed2f19fc",
"post" : "See this cool character !!",
"user" : "Nxmo8Wlhlcg4GDvh7ZIAnmBbpS82"
}
}
}
} and that's what i want to apply
{
"rules": {
".write": true ,
"posts":{
"$pid":{
".read": "data.child('user').val()===auth.uid ||root.child('followers').child(auth.uid).child(data.child('user').val()).val()=== true "
}
},
"followers":{
".read": true
},
"Users":{
".read": true,
}
}
}
the problem arises when I want to add event listener on "posts" node but as it doesn't have read : true so it doesn't return anything.
the only solution I could think of was to make another tree on same level of posts which will contain all posts names and then i start making single event listener on each post node (replace child(posts) to child(posts + post[i] ))
Is there any better option because in case of 100 post I will make 100 single event task which I think of as time ,memory and Internet unnecessary consuming