I need some advice on how to handle using rethinkDb's change-feeds for multiple users in my node.js app.
Essentially I want when a user logs into our web app, I want to set up a change-feed for that particular user to monitor changes to a particular table filtered by the users organization.
I was thinking that when a user connects, they will also connect via socketio, and i could assign a change-feed for the user on connect. Then close that users cursor on disconnect.
Maybe something like:
io.on('connection', (socket)=> {
//Assume user information is in socket.user
r.db('database').table('entries').filter({organization: socket.user.organization}).changes().run(conn, (err, cursor){
cursor_holder[socket.user.id] = cursor //Maybe hold the cursors in memory while the user is connected?
cursor.each((err, entry)=>{
socket.emit('update', entry);
})
})
socket.on('disconnect', ()=>{
cursor_holder[socket.user.id].close() //I dont know what the exact close method is for the feed.
})
}
Please excuse any errors in the code but this was the initial idea I had to handle my end-goal.
I'm just curious for any suggestions you may have how to properly handle the end-goal I stated earlier.
Thank you all in advance for your time and suggestions. Its greatly appreciated.