I'm developing a module where I need to retrieve all users of a website and check if they have a specific permission.
<?php
$reviewers = array();
$result = db_query('SELECT uid, name FROM {users} ORDER BY uid');
while ($record = db_fetch_object($result)) {
if ($record->uid != 0) {
if (user_access('review article', user_load($record->uid), TRUE)) {
$reviewers[$record->uid] = (string) $record->name . '@domain.com';
}
}
}
I'm using this code and it works but it can become quite slow. I've tested in a site with 5.000 bogus users and it takes about 30 secs to complete.