accesslib: has_capability() now supports fake $USER for forum cron

has_capability() can handle the fake user that forum cron sets up
and will load the appropriate accessdata into $USER->access.

This makes forum cron work again. A test comparison between before
this patchseries yields:

With 1 forum post, sent total 24 times
 - Before 11 000 DB queries (approx)
 - After     506 DB queries

With 6 forum posts, sent a total of 452 times
 - Before 47 876 DB queries
 - After   8 256 DB queries

There is a very high variability, but we are going from 100-500
queries per sent email to 18-21 queries per sent email. The
variability probably stems from 2 of the 6 posts being in a 200-user
forum.

Still huge - by the time we are sending the email, we should know
everything we need to know about the user, the forum/thread/post and
the form. The average should be well below 1 DB query per email sent!
This commit is contained in:
martinlanghoff 2007-09-19 07:20:24 +00:00
parent a5d81e5e5e
commit 1a9b67874f

View File

@ -421,6 +421,22 @@ function has_capability($capability, $context=NULL, $userid=NULL, $doanything=tr
load_all_capabilities();
}
if (FULLME === 'cron' && !isset($USER->access)) {
//
// In cron, some modules setup a 'fake' $USER,
// ensure we load the appropriate accessdata.
// Also: set $DIRTYCONTEXTS to empty
//
if (!isset($ACCESS)) {
$ACCESS = array();
}
if (!isset($ACCESS[$userid])) {
load_user_accessdata($userid);
}
$USER->access = $ACCESS[$userid];
$DIRTYCONTEXTS = array();
}
// Careful check for staleness...
$clean = true;
if (!isset($DIRTYCONTEXTS)) {