mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-15553 events_trigger() perf improvement; merged from MOODLE_19_STABLE
This commit is contained in:
parent
2942a5cd34
commit
1336c96edb
@ -325,7 +325,27 @@ function events_dequeue($qhandler) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns hanflers for given event. Uses caching for better perf.
|
||||||
|
* @param string $eventanme name of even or 'reset'
|
||||||
|
* @return mixed array of handlers or false otherwise
|
||||||
|
*
|
||||||
|
* INTERNAL - to be used from eventslib only
|
||||||
|
*/
|
||||||
|
function events_get_handlers($eventname) {
|
||||||
|
static $handlers = array();
|
||||||
|
|
||||||
|
if ($eventname == 'reset') {
|
||||||
|
$handlers = array();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists($eventname, $handlers)) {
|
||||||
|
$handlers[$eventname] = $DB->get_records('events_handlers', array('eventname'=>$eventname));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $handlers[$eventname];
|
||||||
|
}
|
||||||
|
|
||||||
/****** Public events API starts here, do not use functions above in 3rd party code ******/
|
/****** Public events API starts here, do not use functions above in 3rd party code ******/
|
||||||
|
|
||||||
@ -390,7 +410,7 @@ function events_trigger($eventname, $eventdata) {
|
|||||||
$event = false;
|
$event = false;
|
||||||
|
|
||||||
// pull out all registered event handlers
|
// pull out all registered event handlers
|
||||||
if ($handlers = $DB->get_records('events_handlers', array('eventname'=>$eventname))) {
|
if ($handlers = events_get_handlers($eventname)) {
|
||||||
foreach ($handlers as $handler) {
|
foreach ($handlers as $handler) {
|
||||||
|
|
||||||
$errormessage = '';
|
$errormessage = '';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user