our NodeJS backend application has more than 200K users and every week we do some controls/calculations based on users. The operation is similar to this:
const users = await dbService.user.findMany({}); // Array of 200K+ users
for (let index = 0; index < users.length; index++) {
const user = users[index];
const result = await checkUserSubscriptions({ id: user.id });
// do operations according to result, mostly updateUser in database.
}
During the process, most of other requests are not executed or waited till this operation finishes. For example when a user tries to log in, they wait until this loop ends or they get a big delay. Because this operation does not need to be instant and can have delay or be slow, I need to use something else that does not block our main queue. What can I do to ensure this?