User to role to app relations update upon app creation


I use DF configuration with open registratin enabled. Each registered user got ‘registered’ role upon successfull registration, for each existing application.
Now, assuming we have thousands of users registered, and adding a new application, it would have no role assigned for any existing user.
What I need is to assign ‘registered’ role relation for any existing user for a newly create application.
I’m planning to use an event script for this, namely,
Pleas, correct me if I’ wrong.

  1. As soon as I do not have an access to SQL COUNT(*) on user table, all I can do is to request, say N reqs per one request via limit and offset, and do it until a < N recordset is returned.
  2. For each user id from returned recordset I should check if related role is already there for an application id
  3. If it’s not, I should PUT relation for known user id, app id, and role id
    Looks like it’s not an optimal way, regarding API requests. I mean, for each user we should run two requests, one to check if relation is there, another (may be optional, but for a new application, it 100% will be there), to assign a new relation for a user-to-role-to-app.
    Is there more optimal way to do that?