I am making a pet-project in MERN stack where I want to implement the activity status of users. After 3 minutes of inactivity the user status becomes inactive. One approach i am considering is by node-cron schedular
- Users will have activity status and last seen in their schema and schedular will run every 3-4 minutes and fetches all users with last seen greater than 3 minutes and mark them inactive and a middleware to mark the user active whenever a request is made and update the last seen.
The problem is I think this will be a huge overhead to fetch all users after every 3-4 minutes and change their status resulting in ineffeciency of server.
Please suggest me if this is good approach or how to make it effecient and also if their is some better approach i should go for?